/************************************************************************
       -= SEER - C-Scripting engine v 0.93a =-
State      : under implementation
Author     : Przemyslaw Podsiadly
             email: ppodsiad@elka.pw.edu.pl
             WWW:   http://home.elka.pw.edu.pl/~ppodsiad
File:exinside
Desc:script inside .exe as char* variable, internal headers,
     also accessing script variable
************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <seer.h>

//The script inside your program:----------------------------------------
char *scripty=                                                          
"                                                                       \n"
"/*                                                                      \n"
"    -=the script inside your C-sources!!=-                              \n"
"*/                                                                      \n"
"#include header                                                         \n"
"int i;                                                                  \n"
"                                                                        \n"
"export main;                                                            \n"
"export variable;                                                        \n"
"int variable=0;                                                         \n"
"                                                                        \n"
"int main(int x)                                                         \n"
"{                                                                       \n"
" printf(\"Program called :main(%d)\\n\",x);                             \n"
" switch(x)                                                              \n"
" {                                                                      \n"
"  case 1:printf(\"Was 1\\n\");break;                                    \n"
"  case 2:printf(\"Was 2\\n\");break;                                    \n"
"  default:printf(\"Wasn't 1 nor 2\\n\");                                \n"
" }                                                                      \n"
" printf(\"And variable was set to %d\\n\",variable);                    \n"
" return 2*x;                                                            \n"
"}                                                                       \n"
;

char *header=
"//This is the internal header.                                         \n"
"//Something like 'stdio' internal header in seerc, but smaller         \n"
"#ifndef HEADER_INCLUDED                                                \n"
"import int printf(char *,...);                                         \n"
"#define HEADER_INCLUDED                                                \n"
"#endif									\n"
;
//--------------------------------------------------------------------

void Init_Externals()
{
 scAdd_External_Symbol("printf",printf);
 scAdd_External_Symbol("scanf",scanf);
 scAdd_Internal_Header("header",header);
}

int main()
{
 scScript scrpt;
 scInstance *prog;
 Init_Externals();

//compile char* variable
 scrpt=scCompile_Text(scripty);
 if (scErrorNo)
   {
      printf("%s\n> %s\n",scErrorMsg,scErrorLine);exit(scErrorNo);
   }

 prog=scCreate_Instance(scrpt,"");
 if (!prog)
  {
   printf("Error creating instance!\n");
   return 1;
  }
 //access variable:
 scVar(prog,scGet_Symbol(prog,"variable"),int)=11;

 //and you can get pointer to variable rather easly:
 *(&scVar(prog,scGet_Symbol(prog,"variable"),int))=13;
 //call script
 printf("Result = %d\n",scCall_Instance(prog,scGet_Symbol(prog,"main"),1));
//let's delete instance and script
 scFree_Instance(prog);
 free(scrpt);
 return 0;
}

