/************************************************************************
       -= 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:exsimple
Desc:scanf example and importing own function isqrt
************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <seer.h>

/* Own functions imported by script */
int isqrt(int x)
{return (int)sqrt((double)x);
}

void Init_Externals()
{
 scAdd_External_Symbol("printf",printf);
 scAdd_External_Symbol("scanf",scanf);
 scAdd_External_Symbol("isqrt",isqrt);
 scAdd_External_Symbol("sqrt",sqrt);
}

int main()
{
 scScript scrpt;
 scInstance *prog;
 char *x="Welcome!!!!!!!";

//load example script : exsimple.cs
 Init_Externals();
 scrpt=scLoad_Script("exsimple.cs");
 if (!scrpt)
    {printf("Error loading script!\nPlease compile it using seerc and run exsimple again.\n");
     exit(1);}
 prog=scCreate_Instance(scrpt,"");
 if (!prog)
  {
   printf("Error creating instance!\n");
   return 1;
  }
 scCall_Instance(prog,scGet_Symbol(prog,"main"),x);
//let's delete instance and script
 scFree_Instance(prog);
 free(scrpt);
 return 0;
}

