void PrintVersionInfos() { scfprintf(stdout,_SC("%s %s (%d bits)\n"),SQUIRREL_VERSION,SQUIRREL_COPYRIGHT,sizeof(SQInteger)*8); if(sizeof(SQFloat) != sizeof(float)) { scfprintf(stdout,_SC("[%d bits floats]\n"),sizeof(SQFloat)*8); } }
void PrintUsage() { scfprintf(stderr,_SC("usage: sq <options> <scriptpath [args]>.\n") _SC("Available options are:\n") _SC(" -c compiles the file to bytecode(default output 'out.cnut')\n") _SC(" -o specifies output file for the -c option\n") _SC(" -c compiles only\n") _SC(" -d generates debug infos\n") _SC(" -v displays version infos\n") _SC(" -h prints help\n")); }
void Squirrel::ErrorPrintFunc(HSQUIRRELVM vm, const SQChar *s, ...) { va_list arglist; SQChar buf[1024]; va_start(arglist, s); scvsnprintf(buf, lengthof(buf), s, arglist); va_end(arglist); /* Check if we have a custom print function */ SQPrintFunc *func = ((Squirrel *)sq_getforeignptr(vm))->print_func; if (func == NULL) { scfprintf(stderr, _SC("%s"), buf); } else { (*func)(true, buf); } }
void Squirrel::CompileError(HSQUIRRELVM vm, const SQChar *desc, const SQChar *source, SQInteger line, SQInteger column) { SQChar buf[1024]; #ifdef _SQ64 scsnprintf(buf, lengthof(buf), _SC("Error %s:%ld/%ld: %s"), source, line, column, desc); #else scsnprintf(buf, lengthof(buf), _SC("Error %s:%d/%d: %s"), source, line, column, desc); #endif /* Check if we have a custom print function */ Squirrel *engine = (Squirrel *)sq_getforeignptr(vm); engine->crashed = true; SQPrintFunc *func = engine->print_func; if (func == NULL) { scfprintf(stderr, _SC("%s"), buf); } else { (*func)(true, buf); } }
void Squirrel::RunError(HSQUIRRELVM vm, const SQChar *error) { /* Set the print function to something that prints to stderr */ SQPRINTFUNCTION pf = sq_getprintfunc(vm); sq_setprintfunc(vm, &Squirrel::ErrorPrintFunc); /* Check if we have a custom print function */ SQChar buf[1024]; scsnprintf(buf, lengthof(buf), _SC("Your script made an error: %s\n"), error); Squirrel *engine = (Squirrel *)sq_getforeignptr(vm); SQPrintFunc *func = engine->print_func; if (func == NULL) { scfprintf(stderr, _SC("%s"), buf); } else { (*func)(true, buf); } /* Print below the error the stack, so the users knows what is happening */ sqstd_printcallstack(vm); /* Reset the old print function */ sq_setprintfunc(vm, pf); }
void PrintVersionInfos() { scfprintf(stdout,_SC("%s %s (%d bits)\n"),SQUIRREL_VERSION,SQUIRREL_COPYRIGHT,((int)(sizeof(SQInteger)*8))); }
void Interactive(HSQUIRRELVM v) { #define MAXINPUT 1024 SQChar buffer[MAXINPUT]; SQInteger blocks =0; SQInteger string=0; SQInteger retval=0; SQInteger done=0; PrintVersionInfos(); sq_pushroottable(v); sq_pushstring(v,_SC("quit"),-1); sq_pushuserpointer(v,&done); sq_newclosure(v,quit,1); sq_setparamscheck(v,1,NULL); sq_newslot(v,-3,SQFalse); sq_pop(v,1); while (!done) { SQInteger i = 0; scprintf(_SC("\nsq>")); for(;;) { int c; if(done)return; c = getchar(); if (c == _SC('\n')) { if (i>0 && buffer[i-1] == _SC('\\')) { buffer[i-1] = _SC('\n'); } else if(blocks==0)break; buffer[i++] = _SC('\n'); } else if (c==_SC('}')) {blocks--; buffer[i++] = (SQChar)c;} else if(c==_SC('{') && !string){ blocks++; buffer[i++] = (SQChar)c; } else if(c==_SC('"') || c==_SC('\'')){ string=!string; buffer[i++] = (SQChar)c; } else if (i >= MAXINPUT-1) { scfprintf(stderr, _SC("sq : input line too long\n")); break; } else{ buffer[i++] = (SQChar)c; } } buffer[i] = _SC('\0'); if(buffer[0]==_SC('=')){ scsprintf(sq_getscratchpad(v,MAXINPUT),_SC("return (%s)"),&buffer[1]); memcpy(buffer,sq_getscratchpad(v,-1),(scstrlen(sq_getscratchpad(v,-1))+1)*sizeof(SQChar)); retval=1; } i=scstrlen(buffer); if(i>0){ SQInteger oldtop=sq_gettop(v); if(SQ_SUCCEEDED(sq_compilebuffer(v,buffer,i,_SC("interactive console"),SQTrue))){ sq_pushroottable(v); if(SQ_SUCCEEDED(sq_call(v,1,retval,SQTrue)) && retval){ scprintf(_SC("\n")); sq_pushroottable(v); sq_pushstring(v,_SC("print"),-1); sq_get(v,-2); sq_pushroottable(v); sq_push(v,-4); sq_call(v,2,SQFalse,SQTrue); retval=0; scprintf(_SC("\n")); } } sq_settop(v,oldtop); } } }
void PrintVersionInfos() { scfprintf(stdout,_SC("%s %s (%d bits)\n"),PSCRIPT_VERSION,PSCRIPT_COPYRIGHT,((int)(sizeof(PSInteger)*8))); }