The Squirrel interpreter. See http://www.squirrel-lang.org/

Dependents:   Squirrel

Committer:
jhnwkmn
Date:
Tue Dec 16 11:21:09 2014 +0000
Revision:
1:8a2835ae5c5d
Parent:
0:97a4f8cc534c
Child:
3:7268a3ceaffc
Added hooks into mbed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jhnwkmn 0:97a4f8cc534c 1 /* see copyright notice in squirrel.h */
jhnwkmn 0:97a4f8cc534c 2
jhnwkmn 0:97a4f8cc534c 3 #include <stdio.h>
jhnwkmn 0:97a4f8cc534c 4 #include <stdlib.h>
jhnwkmn 0:97a4f8cc534c 5 #include <string.h>
jhnwkmn 0:97a4f8cc534c 6 #include <stdarg.h>
jhnwkmn 0:97a4f8cc534c 7
jhnwkmn 0:97a4f8cc534c 8 #if defined(_MSC_VER) && defined(_DEBUG)
jhnwkmn 0:97a4f8cc534c 9 #include <crtdbg.h>
jhnwkmn 0:97a4f8cc534c 10 #include <conio.h>
jhnwkmn 0:97a4f8cc534c 11 #endif
jhnwkmn 0:97a4f8cc534c 12 #include <squirrel.h>
jhnwkmn 0:97a4f8cc534c 13 #include <sqstdblob.h>
jhnwkmn 0:97a4f8cc534c 14 #include <sqstdsystem.h>
jhnwkmn 0:97a4f8cc534c 15 #include <sqstdio.h>
jhnwkmn 0:97a4f8cc534c 16 #include <sqstdmath.h>
jhnwkmn 0:97a4f8cc534c 17 #include <sqstdstring.h>
jhnwkmn 0:97a4f8cc534c 18 #include <sqstdaux.h>
jhnwkmn 0:97a4f8cc534c 19
jhnwkmn 0:97a4f8cc534c 20 #ifdef SQUNICODE
jhnwkmn 0:97a4f8cc534c 21 #define scfprintf fwprintf
jhnwkmn 0:97a4f8cc534c 22 #define scfopen _wfopen
jhnwkmn 0:97a4f8cc534c 23 #define scvprintf vfwprintf
jhnwkmn 0:97a4f8cc534c 24 #else
jhnwkmn 0:97a4f8cc534c 25 #define scfprintf fprintf
jhnwkmn 0:97a4f8cc534c 26 #define scfopen fopen
jhnwkmn 0:97a4f8cc534c 27 #define scvprintf vfprintf
jhnwkmn 0:97a4f8cc534c 28 #endif
jhnwkmn 0:97a4f8cc534c 29
jhnwkmn 0:97a4f8cc534c 30
jhnwkmn 0:97a4f8cc534c 31 void PrintVersionInfos();
jhnwkmn 0:97a4f8cc534c 32
jhnwkmn 0:97a4f8cc534c 33 #if defined(_MSC_VER) && defined(_DEBUG)
jhnwkmn 0:97a4f8cc534c 34 int MemAllocHook( int allocType, void *userData, size_t size, int blockType,
jhnwkmn 0:97a4f8cc534c 35 long requestNumber, const unsigned char *filename, int lineNumber)
jhnwkmn 0:97a4f8cc534c 36 {
jhnwkmn 0:97a4f8cc534c 37 //if(requestNumber==769)_asm int 3;
jhnwkmn 0:97a4f8cc534c 38 return 1;
jhnwkmn 0:97a4f8cc534c 39 }
jhnwkmn 0:97a4f8cc534c 40 #endif
jhnwkmn 0:97a4f8cc534c 41
jhnwkmn 0:97a4f8cc534c 42
jhnwkmn 0:97a4f8cc534c 43 SQInteger quit(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 44 {
jhnwkmn 0:97a4f8cc534c 45 int *done;
jhnwkmn 0:97a4f8cc534c 46 sq_getuserpointer(v,-1,(SQUserPointer*)&done);
jhnwkmn 0:97a4f8cc534c 47 *done=1;
jhnwkmn 0:97a4f8cc534c 48 return 0;
jhnwkmn 0:97a4f8cc534c 49 }
jhnwkmn 0:97a4f8cc534c 50
jhnwkmn 0:97a4f8cc534c 51 void printfunc(HSQUIRRELVM v,const SQChar *s,...)
jhnwkmn 0:97a4f8cc534c 52 {
jhnwkmn 0:97a4f8cc534c 53 va_list vl;
jhnwkmn 0:97a4f8cc534c 54 va_start(vl, s);
jhnwkmn 0:97a4f8cc534c 55 scvprintf(stdout, s, vl);
jhnwkmn 0:97a4f8cc534c 56 va_end(vl);
jhnwkmn 0:97a4f8cc534c 57 }
jhnwkmn 0:97a4f8cc534c 58
jhnwkmn 0:97a4f8cc534c 59 void errorfunc(HSQUIRRELVM v,const SQChar *s,...)
jhnwkmn 0:97a4f8cc534c 60 {
jhnwkmn 0:97a4f8cc534c 61 va_list vl;
jhnwkmn 0:97a4f8cc534c 62 va_start(vl, s);
jhnwkmn 0:97a4f8cc534c 63 scvprintf(stderr, s, vl);
jhnwkmn 0:97a4f8cc534c 64 va_end(vl);
jhnwkmn 0:97a4f8cc534c 65 }
jhnwkmn 0:97a4f8cc534c 66
jhnwkmn 0:97a4f8cc534c 67 void PrintVersionInfos()
jhnwkmn 0:97a4f8cc534c 68 {
jhnwkmn 0:97a4f8cc534c 69 scfprintf(stdout,_SC("%s %s (%d bits)\n"),SQUIRREL_VERSION,SQUIRREL_COPYRIGHT,((int)(sizeof(SQInteger)*8)));
jhnwkmn 0:97a4f8cc534c 70 }
jhnwkmn 0:97a4f8cc534c 71
jhnwkmn 0:97a4f8cc534c 72 void PrintUsage()
jhnwkmn 0:97a4f8cc534c 73 {
jhnwkmn 0:97a4f8cc534c 74 scfprintf(stderr,_SC("usage: sq <options> <scriptpath [args]>.\n")
jhnwkmn 0:97a4f8cc534c 75 _SC("Available options are:\n")
jhnwkmn 0:97a4f8cc534c 76 _SC(" -c compiles the file to bytecode(default output 'out.cnut')\n")
jhnwkmn 0:97a4f8cc534c 77 _SC(" -o specifies output file for the -c option\n")
jhnwkmn 0:97a4f8cc534c 78 _SC(" -c compiles only\n")
jhnwkmn 0:97a4f8cc534c 79 _SC(" -d generates debug infos\n")
jhnwkmn 0:97a4f8cc534c 80 _SC(" -v displays version infos\n")
jhnwkmn 0:97a4f8cc534c 81 _SC(" -h prints help\n"));
jhnwkmn 0:97a4f8cc534c 82 }
jhnwkmn 0:97a4f8cc534c 83
jhnwkmn 0:97a4f8cc534c 84 #define _INTERACTIVE 0
jhnwkmn 0:97a4f8cc534c 85 #define _DONE 2
jhnwkmn 0:97a4f8cc534c 86 #define _ERROR 3
jhnwkmn 0:97a4f8cc534c 87 //<<FIXME>> this func is a mess
jhnwkmn 0:97a4f8cc534c 88 int getargs(HSQUIRRELVM v,int argc, char* argv[],SQInteger *retval)
jhnwkmn 0:97a4f8cc534c 89 {
jhnwkmn 0:97a4f8cc534c 90 int i;
jhnwkmn 0:97a4f8cc534c 91 int compiles_only = 0;
jhnwkmn 0:97a4f8cc534c 92 static SQChar temp[500];
jhnwkmn 0:97a4f8cc534c 93 const SQChar *ret=NULL;
jhnwkmn 0:97a4f8cc534c 94 char * output = NULL;
jhnwkmn 0:97a4f8cc534c 95 int lineinfo=0;
jhnwkmn 0:97a4f8cc534c 96 *retval = 0;
jhnwkmn 0:97a4f8cc534c 97 if(argc>1)
jhnwkmn 0:97a4f8cc534c 98 {
jhnwkmn 0:97a4f8cc534c 99 int arg=1,exitloop=0;
jhnwkmn 0:97a4f8cc534c 100
jhnwkmn 0:97a4f8cc534c 101 while(arg < argc && !exitloop)
jhnwkmn 0:97a4f8cc534c 102 {
jhnwkmn 0:97a4f8cc534c 103
jhnwkmn 0:97a4f8cc534c 104 if(argv[arg][0]=='-')
jhnwkmn 0:97a4f8cc534c 105 {
jhnwkmn 0:97a4f8cc534c 106 switch(argv[arg][1])
jhnwkmn 0:97a4f8cc534c 107 {
jhnwkmn 0:97a4f8cc534c 108 case 'd': //DEBUG(debug infos)
jhnwkmn 0:97a4f8cc534c 109 sq_enabledebuginfo(v,1);
jhnwkmn 0:97a4f8cc534c 110 break;
jhnwkmn 0:97a4f8cc534c 111 case 'c':
jhnwkmn 0:97a4f8cc534c 112 compiles_only = 1;
jhnwkmn 0:97a4f8cc534c 113 break;
jhnwkmn 0:97a4f8cc534c 114 case 'o':
jhnwkmn 0:97a4f8cc534c 115 if(arg < argc) {
jhnwkmn 0:97a4f8cc534c 116 arg++;
jhnwkmn 0:97a4f8cc534c 117 output = argv[arg];
jhnwkmn 0:97a4f8cc534c 118 }
jhnwkmn 0:97a4f8cc534c 119 break;
jhnwkmn 0:97a4f8cc534c 120 case 'v':
jhnwkmn 0:97a4f8cc534c 121 PrintVersionInfos();
jhnwkmn 0:97a4f8cc534c 122 return _DONE;
jhnwkmn 0:97a4f8cc534c 123
jhnwkmn 0:97a4f8cc534c 124 case 'h':
jhnwkmn 0:97a4f8cc534c 125 PrintVersionInfos();
jhnwkmn 0:97a4f8cc534c 126 PrintUsage();
jhnwkmn 0:97a4f8cc534c 127 return _DONE;
jhnwkmn 0:97a4f8cc534c 128 default:
jhnwkmn 0:97a4f8cc534c 129 PrintVersionInfos();
jhnwkmn 0:97a4f8cc534c 130 scprintf(_SC("unknown prameter '-%c'\n"),argv[arg][1]);
jhnwkmn 0:97a4f8cc534c 131 PrintUsage();
jhnwkmn 0:97a4f8cc534c 132 *retval = -1;
jhnwkmn 0:97a4f8cc534c 133 return _ERROR;
jhnwkmn 0:97a4f8cc534c 134 }
jhnwkmn 0:97a4f8cc534c 135 }else break;
jhnwkmn 0:97a4f8cc534c 136 arg++;
jhnwkmn 0:97a4f8cc534c 137 }
jhnwkmn 0:97a4f8cc534c 138
jhnwkmn 0:97a4f8cc534c 139 // src file
jhnwkmn 0:97a4f8cc534c 140
jhnwkmn 0:97a4f8cc534c 141 if(arg<argc) {
jhnwkmn 0:97a4f8cc534c 142 const SQChar *filename=NULL;
jhnwkmn 0:97a4f8cc534c 143 #ifdef SQUNICODE
jhnwkmn 0:97a4f8cc534c 144 mbstowcs(temp,argv[arg],strlen(argv[arg]));
jhnwkmn 0:97a4f8cc534c 145 filename=temp;
jhnwkmn 0:97a4f8cc534c 146 #else
jhnwkmn 0:97a4f8cc534c 147 filename=argv[arg];
jhnwkmn 0:97a4f8cc534c 148 #endif
jhnwkmn 0:97a4f8cc534c 149
jhnwkmn 0:97a4f8cc534c 150 arg++;
jhnwkmn 0:97a4f8cc534c 151
jhnwkmn 0:97a4f8cc534c 152 //sq_pushstring(v,_SC("ARGS"),-1);
jhnwkmn 0:97a4f8cc534c 153 //sq_newarray(v,0);
jhnwkmn 0:97a4f8cc534c 154
jhnwkmn 0:97a4f8cc534c 155 //sq_createslot(v,-3);
jhnwkmn 0:97a4f8cc534c 156 //sq_pop(v,1);
jhnwkmn 0:97a4f8cc534c 157 if(compiles_only) {
jhnwkmn 0:97a4f8cc534c 158 if(SQ_SUCCEEDED(sqstd_loadfile(v,filename,SQTrue))){
jhnwkmn 0:97a4f8cc534c 159 const SQChar *outfile = _SC("out.cnut");
jhnwkmn 0:97a4f8cc534c 160 if(output) {
jhnwkmn 0:97a4f8cc534c 161 #ifdef SQUNICODE
jhnwkmn 0:97a4f8cc534c 162 int len = (int)(strlen(output)+1);
jhnwkmn 0:97a4f8cc534c 163 mbstowcs(sq_getscratchpad(v,len*sizeof(SQChar)),output,len);
jhnwkmn 0:97a4f8cc534c 164 outfile = sq_getscratchpad(v,-1);
jhnwkmn 0:97a4f8cc534c 165 #else
jhnwkmn 0:97a4f8cc534c 166 outfile = output;
jhnwkmn 0:97a4f8cc534c 167 #endif
jhnwkmn 0:97a4f8cc534c 168 }
jhnwkmn 0:97a4f8cc534c 169 if(SQ_SUCCEEDED(sqstd_writeclosuretofile(v,outfile)))
jhnwkmn 0:97a4f8cc534c 170 return _DONE;
jhnwkmn 0:97a4f8cc534c 171 }
jhnwkmn 0:97a4f8cc534c 172 }
jhnwkmn 0:97a4f8cc534c 173 else {
jhnwkmn 0:97a4f8cc534c 174 //if(SQ_SUCCEEDED(sqstd_dofile(v,filename,SQFalse,SQTrue))) {
jhnwkmn 0:97a4f8cc534c 175 //return _DONE;
jhnwkmn 0:97a4f8cc534c 176 //}
jhnwkmn 0:97a4f8cc534c 177 if(SQ_SUCCEEDED(sqstd_loadfile(v,filename,SQTrue))) {
jhnwkmn 0:97a4f8cc534c 178 int callargs = 1;
jhnwkmn 0:97a4f8cc534c 179 sq_pushroottable(v);
jhnwkmn 0:97a4f8cc534c 180 for(i=arg;i<argc;i++)
jhnwkmn 0:97a4f8cc534c 181 {
jhnwkmn 0:97a4f8cc534c 182 const SQChar *a;
jhnwkmn 0:97a4f8cc534c 183 #ifdef SQUNICODE
jhnwkmn 0:97a4f8cc534c 184 int alen=(int)strlen(argv[i]);
jhnwkmn 0:97a4f8cc534c 185 a=sq_getscratchpad(v,(int)(alen*sizeof(SQChar)));
jhnwkmn 0:97a4f8cc534c 186 mbstowcs(sq_getscratchpad(v,-1),argv[i],alen);
jhnwkmn 0:97a4f8cc534c 187 sq_getscratchpad(v,-1)[alen] = _SC('\0');
jhnwkmn 0:97a4f8cc534c 188 #else
jhnwkmn 0:97a4f8cc534c 189 a=argv[i];
jhnwkmn 0:97a4f8cc534c 190 #endif
jhnwkmn 0:97a4f8cc534c 191 sq_pushstring(v,a,-1);
jhnwkmn 0:97a4f8cc534c 192 callargs++;
jhnwkmn 0:97a4f8cc534c 193 //sq_arrayappend(v,-2);
jhnwkmn 0:97a4f8cc534c 194 }
jhnwkmn 0:97a4f8cc534c 195 if(SQ_SUCCEEDED(sq_call(v,callargs,SQTrue,SQTrue))) {
jhnwkmn 0:97a4f8cc534c 196 SQObjectType type = sq_gettype(v,-1);
jhnwkmn 0:97a4f8cc534c 197 if(type == OT_INTEGER) {
jhnwkmn 0:97a4f8cc534c 198 *retval = type;
jhnwkmn 0:97a4f8cc534c 199 sq_getinteger(v,-1,retval);
jhnwkmn 0:97a4f8cc534c 200 }
jhnwkmn 0:97a4f8cc534c 201 return _DONE;
jhnwkmn 0:97a4f8cc534c 202 }
jhnwkmn 0:97a4f8cc534c 203 else{
jhnwkmn 0:97a4f8cc534c 204 return _ERROR;
jhnwkmn 0:97a4f8cc534c 205 }
jhnwkmn 0:97a4f8cc534c 206
jhnwkmn 0:97a4f8cc534c 207 }
jhnwkmn 0:97a4f8cc534c 208 }
jhnwkmn 0:97a4f8cc534c 209 //if this point is reached an error occured
jhnwkmn 0:97a4f8cc534c 210 {
jhnwkmn 0:97a4f8cc534c 211 const SQChar *err;
jhnwkmn 0:97a4f8cc534c 212 sq_getlasterror(v);
jhnwkmn 0:97a4f8cc534c 213 if(SQ_SUCCEEDED(sq_getstring(v,-1,&err))) {
jhnwkmn 0:97a4f8cc534c 214 scprintf(_SC("Error [%s]\n"),err);
jhnwkmn 0:97a4f8cc534c 215 *retval = -2;
jhnwkmn 0:97a4f8cc534c 216 return _ERROR;
jhnwkmn 0:97a4f8cc534c 217 }
jhnwkmn 0:97a4f8cc534c 218 }
jhnwkmn 0:97a4f8cc534c 219
jhnwkmn 0:97a4f8cc534c 220 }
jhnwkmn 0:97a4f8cc534c 221 }
jhnwkmn 0:97a4f8cc534c 222
jhnwkmn 0:97a4f8cc534c 223 return _INTERACTIVE;
jhnwkmn 0:97a4f8cc534c 224 }
jhnwkmn 0:97a4f8cc534c 225
jhnwkmn 0:97a4f8cc534c 226 void Interactive(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 227 {
jhnwkmn 0:97a4f8cc534c 228
jhnwkmn 0:97a4f8cc534c 229 #define MAXINPUT 1024
jhnwkmn 0:97a4f8cc534c 230 SQChar buffer[MAXINPUT];
jhnwkmn 0:97a4f8cc534c 231 SQInteger blocks =0;
jhnwkmn 0:97a4f8cc534c 232 SQInteger string=0;
jhnwkmn 0:97a4f8cc534c 233 SQInteger retval=0;
jhnwkmn 0:97a4f8cc534c 234 SQInteger done=0;
jhnwkmn 0:97a4f8cc534c 235 PrintVersionInfos();
jhnwkmn 0:97a4f8cc534c 236
jhnwkmn 0:97a4f8cc534c 237 sq_pushroottable(v);
jhnwkmn 0:97a4f8cc534c 238 sq_pushstring(v,_SC("quit"),-1);
jhnwkmn 0:97a4f8cc534c 239 sq_pushuserpointer(v,&done);
jhnwkmn 0:97a4f8cc534c 240 sq_newclosure(v,quit,1);
jhnwkmn 0:97a4f8cc534c 241 sq_setparamscheck(v,1,NULL);
jhnwkmn 0:97a4f8cc534c 242 sq_newslot(v,-3,SQFalse);
jhnwkmn 0:97a4f8cc534c 243 sq_pop(v,1);
jhnwkmn 0:97a4f8cc534c 244
jhnwkmn 0:97a4f8cc534c 245 while (!done)
jhnwkmn 0:97a4f8cc534c 246 {
jhnwkmn 0:97a4f8cc534c 247 SQInteger i = 0;
jhnwkmn 0:97a4f8cc534c 248 scprintf(_SC("\nsq>"));
jhnwkmn 0:97a4f8cc534c 249 for(;;) {
jhnwkmn 0:97a4f8cc534c 250 int c;
jhnwkmn 0:97a4f8cc534c 251 if(done)return;
jhnwkmn 0:97a4f8cc534c 252 c = getchar();
jhnwkmn 0:97a4f8cc534c 253 if (c == _SC('\n')) {
jhnwkmn 0:97a4f8cc534c 254 if (i>0 && buffer[i-1] == _SC('\\'))
jhnwkmn 0:97a4f8cc534c 255 {
jhnwkmn 0:97a4f8cc534c 256 buffer[i-1] = _SC('\n');
jhnwkmn 0:97a4f8cc534c 257 }
jhnwkmn 0:97a4f8cc534c 258 else if(blocks==0)break;
jhnwkmn 0:97a4f8cc534c 259 buffer[i++] = _SC('\n');
jhnwkmn 0:97a4f8cc534c 260 }
jhnwkmn 0:97a4f8cc534c 261 else if (c==_SC('}')) {blocks--; buffer[i++] = (SQChar)c;}
jhnwkmn 0:97a4f8cc534c 262 else if(c==_SC('{') && !string){
jhnwkmn 0:97a4f8cc534c 263 blocks++;
jhnwkmn 0:97a4f8cc534c 264 buffer[i++] = (SQChar)c;
jhnwkmn 0:97a4f8cc534c 265 }
jhnwkmn 0:97a4f8cc534c 266 else if(c==_SC('"') || c==_SC('\'')){
jhnwkmn 0:97a4f8cc534c 267 string=!string;
jhnwkmn 0:97a4f8cc534c 268 buffer[i++] = (SQChar)c;
jhnwkmn 0:97a4f8cc534c 269 }
jhnwkmn 0:97a4f8cc534c 270 else if (i >= MAXINPUT-1) {
jhnwkmn 0:97a4f8cc534c 271 scfprintf(stderr, _SC("sq : input line too long\n"));
jhnwkmn 0:97a4f8cc534c 272 break;
jhnwkmn 0:97a4f8cc534c 273 }
jhnwkmn 0:97a4f8cc534c 274 else{
jhnwkmn 0:97a4f8cc534c 275 buffer[i++] = (SQChar)c;
jhnwkmn 0:97a4f8cc534c 276 }
jhnwkmn 0:97a4f8cc534c 277 }
jhnwkmn 0:97a4f8cc534c 278 buffer[i] = _SC('\0');
jhnwkmn 0:97a4f8cc534c 279
jhnwkmn 0:97a4f8cc534c 280 if(buffer[0]==_SC('=')){
jhnwkmn 0:97a4f8cc534c 281 scsprintf(sq_getscratchpad(v,MAXINPUT),_SC("return (%s)"),&buffer[1]);
jhnwkmn 0:97a4f8cc534c 282 memcpy(buffer,sq_getscratchpad(v,-1),(scstrlen(sq_getscratchpad(v,-1))+1)*sizeof(SQChar));
jhnwkmn 0:97a4f8cc534c 283 retval=1;
jhnwkmn 0:97a4f8cc534c 284 }
jhnwkmn 0:97a4f8cc534c 285 i=scstrlen(buffer);
jhnwkmn 0:97a4f8cc534c 286 if(i>0){
jhnwkmn 0:97a4f8cc534c 287 SQInteger oldtop=sq_gettop(v);
jhnwkmn 0:97a4f8cc534c 288 if(SQ_SUCCEEDED(sq_compilebuffer(v,buffer,i,_SC("interactive console"),SQTrue))){
jhnwkmn 0:97a4f8cc534c 289 sq_pushroottable(v);
jhnwkmn 0:97a4f8cc534c 290 if(SQ_SUCCEEDED(sq_call(v,1,retval,SQTrue)) && retval){
jhnwkmn 0:97a4f8cc534c 291 scprintf(_SC("\n"));
jhnwkmn 0:97a4f8cc534c 292 sq_pushroottable(v);
jhnwkmn 0:97a4f8cc534c 293 sq_pushstring(v,_SC("print"),-1);
jhnwkmn 0:97a4f8cc534c 294 sq_get(v,-2);
jhnwkmn 0:97a4f8cc534c 295 sq_pushroottable(v);
jhnwkmn 0:97a4f8cc534c 296 sq_push(v,-4);
jhnwkmn 0:97a4f8cc534c 297 sq_call(v,2,SQFalse,SQTrue);
jhnwkmn 0:97a4f8cc534c 298 retval=0;
jhnwkmn 0:97a4f8cc534c 299 scprintf(_SC("\n"));
jhnwkmn 0:97a4f8cc534c 300 }
jhnwkmn 0:97a4f8cc534c 301 }
jhnwkmn 0:97a4f8cc534c 302
jhnwkmn 0:97a4f8cc534c 303 sq_settop(v,oldtop);
jhnwkmn 0:97a4f8cc534c 304 }
jhnwkmn 0:97a4f8cc534c 305 }
jhnwkmn 0:97a4f8cc534c 306 }
jhnwkmn 0:97a4f8cc534c 307
jhnwkmn 0:97a4f8cc534c 308 int main(int argc, char* argv[])
jhnwkmn 0:97a4f8cc534c 309 {
jhnwkmn 0:97a4f8cc534c 310 HSQUIRRELVM v;
jhnwkmn 0:97a4f8cc534c 311 SQInteger retval = 0;
jhnwkmn 0:97a4f8cc534c 312 const SQChar *filename=NULL;
jhnwkmn 0:97a4f8cc534c 313 #if defined(_MSC_VER) && defined(_DEBUG)
jhnwkmn 0:97a4f8cc534c 314 _CrtSetAllocHook(MemAllocHook);
jhnwkmn 0:97a4f8cc534c 315 #endif
jhnwkmn 0:97a4f8cc534c 316
jhnwkmn 0:97a4f8cc534c 317 v=sq_open(1024);
jhnwkmn 0:97a4f8cc534c 318 sq_setprintfunc(v,printfunc,errorfunc);
jhnwkmn 0:97a4f8cc534c 319
jhnwkmn 0:97a4f8cc534c 320 sq_pushroottable(v);
jhnwkmn 0:97a4f8cc534c 321
jhnwkmn 0:97a4f8cc534c 322 sqstd_register_bloblib(v);
jhnwkmn 0:97a4f8cc534c 323 sqstd_register_iolib(v);
jhnwkmn 0:97a4f8cc534c 324 sqstd_register_systemlib(v);
jhnwkmn 0:97a4f8cc534c 325 sqstd_register_mathlib(v);
jhnwkmn 0:97a4f8cc534c 326 sqstd_register_stringlib(v);
jhnwkmn 0:97a4f8cc534c 327
jhnwkmn 1:8a2835ae5c5d 328 #if defined(__MBED__)
jhnwkmn 1:8a2835ae5c5d 329 void sq_bind_mbed(HSQUIRRELVM);
jhnwkmn 1:8a2835ae5c5d 330
jhnwkmn 1:8a2835ae5c5d 331 sq_bind_mbed(v);
jhnwkmn 1:8a2835ae5c5d 332 #endif
jhnwkmn 0:97a4f8cc534c 333 //aux library
jhnwkmn 0:97a4f8cc534c 334 //sets error handlers
jhnwkmn 0:97a4f8cc534c 335 sqstd_seterrorhandlers(v);
jhnwkmn 0:97a4f8cc534c 336
jhnwkmn 0:97a4f8cc534c 337 //gets arguments
jhnwkmn 0:97a4f8cc534c 338 switch(getargs(v,argc,argv,&retval))
jhnwkmn 0:97a4f8cc534c 339 {
jhnwkmn 0:97a4f8cc534c 340 case _INTERACTIVE:
jhnwkmn 0:97a4f8cc534c 341 Interactive(v);
jhnwkmn 0:97a4f8cc534c 342 break;
jhnwkmn 0:97a4f8cc534c 343 case _DONE:
jhnwkmn 0:97a4f8cc534c 344 case _ERROR:
jhnwkmn 0:97a4f8cc534c 345 default:
jhnwkmn 0:97a4f8cc534c 346 break;
jhnwkmn 0:97a4f8cc534c 347 }
jhnwkmn 0:97a4f8cc534c 348
jhnwkmn 0:97a4f8cc534c 349 sq_close(v);
jhnwkmn 0:97a4f8cc534c 350
jhnwkmn 0:97a4f8cc534c 351 #if defined(_MSC_VER) && defined(_DEBUG)
jhnwkmn 0:97a4f8cc534c 352 _getch();
jhnwkmn 0:97a4f8cc534c 353 _CrtMemDumpAllObjectsSince( NULL );
jhnwkmn 0:97a4f8cc534c 354 #endif
jhnwkmn 0:97a4f8cc534c 355 return retval;
jhnwkmn 0:97a4f8cc534c 356 }
jhnwkmn 0:97a4f8cc534c 357