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