Clean up includes and definitions in squirrel code
[openttd/fttd.git] / src / 3rdparty / squirrel / etc / minimal.c
blob5fe5d9c9c146bb06181c1d3fe9c35c2ba3b3fa5d
1 #include <stdarg.h>
2 #include <stdio.h>
4 #include <squirrel.h>
5 #include <sqstdaux.h>
7 #ifdef _MSC_VER
8 #pragma comment (lib ,"squirrel.lib")
9 #pragma comment (lib ,"sqstdlib.lib")
10 #endif
12 #define scvprintf vprintf
14 void printfunc(HSQUIRRELVM v, const char *s, ...)
16 va_list arglist;
17 va_start(arglist, s);
18 vprintf(s, arglist);
19 va_end(arglist);
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)
29 sq_pushinteger(v,n);
30 sq_pushfloat(v,f);
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[])
39 HSQUIRRELVM v;
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
55 sq_close(v);
57 return 0;