/************************************************************************
       -= SEER - C-Scripting engine v 0.94a =-
State      : under implementation
Author     : Przemyslaw Podsiadly
             email: ppodsiad@elka.pw.edu.pl
             WWW:   http://home.elka.pw.edu.pl/~ppodsiad
File:exstdlib.c
Desc:example of stdlib header: classes string
************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <seer.h>

/*
This function tells SeeR addresses of functions and variables it can
use (import). If script imports symbol you don't tell the address SeeR
will complain : unresolved reference.Here we use only printf, but we
can add also scanf. In this way you also add variables.
*/
void Init_Externals()
{
 scAdd_External_Symbol("printf",printf);
 scAdd_External_Symbol("scanf",scanf);
}

/*** THE MAIN ***************************************/
int main(int argc,char **argv)
{
//scrpt will contain the compiled script
 scScript scrpt;
//and this is the instance of script, which we can call
//it contains all the data from script.
 scInstance *prog;

//let's give the script access to some functions of ours
 Init_Externals();

//when SeeR is in debug mode, here it will store all debugging data
 scOpen_Debug("exstdlib.dbg");//start debugging

//compile example script : "exstdlib.sc"
 scrpt=scCompile_File("exstdlib.sc");

//Error?
 if (scErrorNo)
   {
      printf("%s\n> %s\n",scErrorMsg,scErrorLine);exit(scErrorNo);
   }

//create instance of the script - you can run only instance of script,
//not script
 prog=scCreate_Instance(scrpt,"");
//Error?
 if (!prog)
  {
   printf("Error creating instance!\n");
   return 1;
  }

//now, let's execute the function (here 'main' has same arguments as out main)
 scCall_Instance(prog,scGet_Symbol(prog,"main"),argc,argv);
//Error?
 if (scErrorNo)
      printf("%s\n",scErrorMsg);

//let's delete instance and script
 scFree_Instance(prog);
 free(scrpt);

//close debugging - close the debug file also
 scClose_Debug();

 return 0;
}

