9
#pragma comment (lib ,"squirrel.lib")
10
#pragma comment (lib ,"sqstdlib.lib")
14
#define scvprintf vwprintf
16
#define scvprintf vprintf
19
void printfunc(HSQUIRRELVM v, const SQChar *s, ...)
23
scvprintf(s, arglist);
27
void call_foo(HSQUIRRELVM v, int n,float f,const SQChar *s)
29
SQInteger top = sq_gettop(v); //saves the stack size before the call
30
sq_pushroottable(v); //pushes the global table
31
sq_pushstring(v,_SC("foo"),-1);
32
if(SQ_SUCCEEDED(sq_get(v,-2))) { //gets the field 'foo' from the global table
33
sq_pushroottable(v); //push the 'this' (in this case is the global table)
36
sq_pushstring(v,s,-1);
37
sq_call(v,4,SQFalse,SQTrue); //calls the function
39
sq_settop(v,top); //restores the original stack size
42
int main(int argc, char* argv[])
45
v = sq_open(1024); // creates a VM with initial stack size 1024
47
//sq_pushroottable(v); //push the root table were to register the lib function
48
//sqstd_register_iolib(v);
49
sqstd_seterrorhandlers(v); //registers the default error handlers
51
sq_setprintfunc(v, printfunc); //sets the print function
53
sq_pushroottable(v); //push the root table(were the globals of the script will be stored)
54
if(SQ_SUCCEEDED(sqstd_dofile(v, _SC("test.nut"), SQFalse, SQTrue))) // also prints syntax errors if any
56
call_foo(v,1,2.5,_SC("teststring"));
59
sq_pop(v,1); //pops the root table