~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/3rdparty/squirrel/etc/minimal.c

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Matthijs Kooijman, Jordi Mallach
  • Date: 2009-04-15 18:22:10 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090415182210-22ktb8kdbp2tf3bm
[ Matthijs Kooijman ]
* New upstream release.
* Remove Debian specific desktop file, upstream provides one now. 
* Add debian/watch file.

[ Jordi Mallach ]
* Bump Standards-Version to 3.8.1, with no changes required.
* Move to debhelper compat 7. Bump Build-Depends accordingly.
* Use dh_prep.
* Add "set -e" to config script.
* Remove a few extra doc files that get installed by upstream Makefile.
* Add more complete copyright information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdarg.h>
 
2
#include <stdio.h>
 
3
 
 
4
#include <squirrel.h>
 
5
#include <sqstdio.h>
 
6
#include <sqstdaux.h>
 
7
 
 
8
#ifdef _MSC_VER
 
9
#pragma comment (lib ,"squirrel.lib")
 
10
#pragma comment (lib ,"sqstdlib.lib")
 
11
#endif
 
12
 
 
13
#ifdef SQUNICODE
 
14
#define scvprintf vwprintf
 
15
#else
 
16
#define scvprintf vprintf
 
17
#endif
 
18
 
 
19
void printfunc(HSQUIRRELVM v, const SQChar *s, ...)
 
20
{
 
21
va_list arglist;
 
22
va_start(arglist, s);
 
23
scvprintf(s, arglist);
 
24
va_end(arglist);
 
25
}
 
26
 
 
27
void call_foo(HSQUIRRELVM v, int n,float f,const SQChar *s)
 
28
{
 
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)
 
34
                sq_pushinteger(v,n);
 
35
                sq_pushfloat(v,f);
 
36
                sq_pushstring(v,s,-1);
 
37
                sq_call(v,4,SQFalse,SQTrue); //calls the function
 
38
        }
 
39
        sq_settop(v,top); //restores the original stack size
 
40
}
 
41
 
 
42
int main(int argc, char* argv[])
 
43
{
 
44
        HSQUIRRELVM v;
 
45
        v = sq_open(1024); // creates a VM with initial stack size 1024
 
46
 
 
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
 
50
 
 
51
        sq_setprintfunc(v, printfunc); //sets the print function
 
52
 
 
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
 
55
        {
 
56
                call_foo(v,1,2.5,_SC("teststring"));
 
57
        }
 
58
 
 
59
        sq_pop(v,1); //pops the root table
 
60
        sq_close(v);
 
61
 
 
62
        return 0;
 
63
}