summaryrefslogtreecommitdiff
path: root/src/3rdparty/squirrel/etc
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-02-25 01:21:50 +0000
committerrubidium <rubidium@openttd.org>2009-02-25 01:21:50 +0000
commit1ad50ce4e6ed74c8eeb89a1f2780e6ed58a72b2b (patch)
tree0955433146cc59335ddaac1d6e08eb177a9ead61 /src/3rdparty/squirrel/etc
parent66a8c0a1325e1f8717150dc6bbe1bcb4fb458bef (diff)
downloadopenttd-1ad50ce4e6ed74c8eeb89a1f2780e6ed58a72b2b.tar.xz
(svn r15578) -Change: unexternalise squirrel.
Diffstat (limited to 'src/3rdparty/squirrel/etc')
-rw-r--r--src/3rdparty/squirrel/etc/minimal.c63
-rw-r--r--src/3rdparty/squirrel/etc/test.nut4
2 files changed, 67 insertions, 0 deletions
diff --git a/src/3rdparty/squirrel/etc/minimal.c b/src/3rdparty/squirrel/etc/minimal.c
new file mode 100644
index 000000000..fc59859f8
--- /dev/null
+++ b/src/3rdparty/squirrel/etc/minimal.c
@@ -0,0 +1,63 @@
+#include <stdarg.h>
+#include <stdio.h>
+
+#include <squirrel.h>
+#include <sqstdio.h>
+#include <sqstdaux.h>
+
+#ifdef _MSC_VER
+#pragma comment (lib ,"squirrel.lib")
+#pragma comment (lib ,"sqstdlib.lib")
+#endif
+
+#ifdef SQUNICODE
+#define scvprintf vwprintf
+#else
+#define scvprintf vprintf
+#endif
+
+void printfunc(HSQUIRRELVM v, const SQChar *s, ...)
+{
+va_list arglist;
+va_start(arglist, s);
+scvprintf(s, arglist);
+va_end(arglist);
+}
+
+void call_foo(HSQUIRRELVM v, int n,float f,const SQChar *s)
+{
+ SQInteger top = sq_gettop(v); //saves the stack size before the call
+ sq_pushroottable(v); //pushes the global table
+ sq_pushstring(v,_SC("foo"),-1);
+ if(SQ_SUCCEEDED(sq_get(v,-2))) { //gets the field 'foo' from the global table
+ sq_pushroottable(v); //push the 'this' (in this case is the global table)
+ sq_pushinteger(v,n);
+ sq_pushfloat(v,f);
+ sq_pushstring(v,s,-1);
+ sq_call(v,4,SQFalse,SQTrue); //calls the function
+ }
+ sq_settop(v,top); //restores the original stack size
+}
+
+int main(int argc, char* argv[])
+{
+ HSQUIRRELVM v;
+ v = sq_open(1024); // creates a VM with initial stack size 1024
+
+ //sq_pushroottable(v); //push the root table were to register the lib function
+ //sqstd_register_iolib(v);
+ sqstd_seterrorhandlers(v); //registers the default error handlers
+
+ sq_setprintfunc(v, printfunc); //sets the print function
+
+ sq_pushroottable(v); //push the root table(were the globals of the script will be stored)
+ if(SQ_SUCCEEDED(sqstd_dofile(v, _SC("test.nut"), SQFalse, SQTrue))) // also prints syntax errors if any
+ {
+ call_foo(v,1,2.5,_SC("teststring"));
+ }
+
+ sq_pop(v,1); //pops the root table
+ sq_close(v);
+
+ return 0;
+}
diff --git a/src/3rdparty/squirrel/etc/test.nut b/src/3rdparty/squirrel/etc/test.nut
new file mode 100644
index 000000000..125df32cd
--- /dev/null
+++ b/src/3rdparty/squirrel/etc/test.nut
@@ -0,0 +1,4 @@
+function foo(i, f, s)
+{
+ print("Called foo(), i="+i+", f="+f+", s='"+s+"'\n");
+}