void flash_device_listup(struct flash_listup *t) { const wgChar *str; HSQUIRRELVM v = qr_open(NULL); SQInteger top = sq_gettop(v); if(SQ_FAILED(sqstd_dofile(v, _SC("flashdevice.nut"), SQFalse, SQTrue))){ // puts("flash device script error"); qr_close(v); return; } int i; const int device_num = flash_device_number_get(v); sq_settop(v, top); for(i = 0; i < device_num; i++){ flash_device_name_get(v, i, &str); if(STRNCMP(str, _SC("dummy"), 6) != 0){ t->append(t->obj_cpu, str); t->append(t->obj_ppu, str); } sq_settop(v, top); } qr_close(v); v = NULL; }
int main(int argc, char* argv[]) { HSQUIRRELVM v; v = sq_open(1024); // creates a VM with initial stack size 1024 //REGISTRATION OF STDLIB //sq_pushroottable(v); //push the root table where the std function will be registered //sqstd_register_iolib(v); //registers a library // ... call here other stdlibs string,math etc... //sq_pop(v,1); //pops the root table //END REGISTRATION OF STDLIB sqstd_seterrorhandlers(v); //registers the default error handlers sq_setprintfunc(v, printfunc,errorfunc); //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; }
int main(int argc, char** argv) { HSQUIRRELVM vm=sq_open(SQUIRREL_STACK_SIZE); sq_setprintfunc(vm, squirrel_print_function, NULL); register_global_func(vm,ShowVersion,"ShowVersion"); register_global_func(vm,Multiply,"Multiply"); if(SQ_FAILED(sqstd_dofile(vm,"test.nut",SQFalse,SQFalse))) return 1; /*const SQChar *program = "::print(\"Hello World!\\n\");"; if (SQ_FAILED(sq_compilebuffer(vm, program, sizeof(SQChar) * strlen(program), "program", SQFalse))) { return 1; }*/ sq_pushroottable(vm); if (SQ_FAILED(sq_call(vm, 1, SQFalse, SQFalse))) { //squirrel_print_last_error(sqvm); return 1; } sq_close(vm); return 0; }
int main(int argc, char *argv[]) { setbuf(stdout, NULL); if (argc < 2) { scprintf(_SC("SQDBG error : no file specified")); return -1; } HSQUIRRELVM v = sq_open(1024); sqstd_seterrorhandlers(v); //!! INITIALIZES THE DEBUGGER ON THE TCP PORT 1234 //!! ENABLES AUTOUPDATE HSQREMOTEDBG rdbg = sq_rdbg_init(v, 1234, SQTrue); if (rdbg) { //!! ENABLES DEBUG INFO GENERATION(for the compiler) sq_enabledebuginfo(v, SQTrue); sq_setprintfunc(v, printfunc, errorfunc); //!! SUSPENDS THE APP UNTIL THE DEBUGGER CLIENT CONNECTS if (SQ_SUCCEEDED(sq_rdbg_waitforconnections(rdbg))) { scprintf(_SC("connected\n")); const SQChar *fname = NULL; #ifdef _UNICODE SQChar sTemp[256]; mbstowcs(sTemp,argv[1],(int)strlen(argv[1])+1); fname=sTemp; #else fname = argv[1]; #endif //!!REGISTERS STANDARDS LIBS sq_pushroottable(v); sqstd_register_bloblib(v); sqstd_register_iolib(v); //!!EXECUTE A SCTIPT if (SQ_FAILED(sqstd_dofile(v, fname, SQFalse, SQTrue))) { PrintError(v); #if defined(_WIN32) || defined(_WIN64) _getch(); #else getch(); #endif } } //!! CLEANUP sq_rdbg_shutdown(rdbg); } else { PrintError(v); } sq_close(v); return 0; }
bool CSquirrel::LoadScript(CString script) { CString scriptPath( "%s/%s", m_pResource->GetPath().Get(), script.Get()); if(SQ_FAILED(sqstd_dofile( m_pVM, scriptPath.Get(), SQFalse, SQTrue ))) { CLogFile::Printf("[%s] Failed to load file %s.", m_pResource->GetName().Get(), script.Get()); return false; } CLogFile::Printf("\t[%s] Loaded file %s.", m_pResource->GetName().Get(), script.Get()); return true; }
bool CSquirrelVM::LoadScript(CString script) { CString scriptPath( "%s/%s", GetResource()->GetResourceDirectoryPath().Get(), script.Get()); if(!SharedUtility::Exists(script.Get()) && SQ_FAILED(sqstd_dofile( m_pVM, scriptPath.Get(), SQFalse, SQTrue ))) { CLogFile::Printf("[%s] Failed to load file %s.", GetResource()->GetName().Get(), script.Get()); return false; } CLogFile::Printf("\t[%s] Loaded file %s.", GetResource()->GetName().Get(), script.Get()); return true; }
bool CSquirrel::Execute() { // Add the script name constant RegisterConstant("SCRIPT_NAME", m_strName); // Add the script path constant RegisterConstant("SCRIPT_PATH", m_strPath); // Load and compile the script if(SQ_FAILED(sqstd_dofile(m_pVM, m_strPath.Get(), SQFalse, SQTrue))) return false; return true; }
bool flash_device_get(const wgChar *name, struct flash_device *t) { HSQUIRRELVM v = qr_open(NULL); if(SQ_FAILED(sqstd_dofile(v, _SC("flashdevice.nut"), SQFalse, SQTrue))){ qr_close(v); return false; } SQInteger top = sq_gettop(v); call(v, name); if(sq_gettype(v, -1) != OT_TABLE){ goto field_error; } t->name = name; if(long_get(v, _SC("capacity"), &t->capacity) == false){ goto field_error; } if(long_get(v, _SC("pagesize"), &t->pagesize) == false){ goto field_error; } if(long_get(v, _SC("erase_wait"), &t->erase_wait) == false){ goto field_error; } if(bool_get(v, _SC("erase_require"), &t->erase_require) == false){ goto field_error; } if(bool_get(v, _SC("retry"), &t->retry) == false){ goto field_error; } if(long_get(v, _SC("command_mask"), &t->command_mask) == false){ goto field_error; } long dd; if(long_get(v, _SC("id_manufacurer"), &dd) == false){ goto field_error; } t->id_manufacurer = dd; if(long_get(v, _SC("id_device"), &dd) == false){ goto field_error; } t->id_device = dd; sq_settop(v, top); qr_close(v); return true; field_error: // puts("script field error"); qr_close(v); return false; }
void MTR_ScriptsDoFile(const char * filename) { SQRESULT error; if (filename == NULL) { MTR_Notify("Unable to run script. Filename is is not valid", 0, MTR_LMT_ERROR); return; } error = sqstd_dofile(mtrVm, filename, 0, 1); if (SQ_FAILED(error)) { MTR_Notify("Error in the script or script file not found.", 0, MTR_DMT_ERROR); } }
ScriptVM::ScriptVM() { 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")); } /*luaVM = NULL; luaVM = lua_open();*/ }
static bool script_execute(HSQUIRRELVM v, const wgChar *function, struct program_config *c) { bool ret = true; if(SQ_FAILED(sqstd_dofile(v, _SC("programcore.nut"), SQFalse, SQTrue))){ c->log.append(c->log.object, wgT("flash core script error\n")); ret = false; }else{ SQRESULT r = qr_call( v, function, (SQUserPointer) c, c->script, 1 + 3 * 2, c->mappernum, c->cpu.memory.transtype, c->cpu.memory.size, c->cpu.flash.capacity, c->ppu.memory.transtype, c->ppu.memory.size, c->cpu.flash.capacity ); if(SQ_FAILED(r)){ ret = false; } } return ret; }
static SQRESULT sq_slave_vm_dofile(HSQUIRRELVM v) { SQ_FUNC_VARS(v); GET_sq_slave_vm_INSTANCE(v, 1); SQ_GET_STRING(v, 2, file_name); SQ_OPT_BOOL(v, 3, retval, false); SQ_OPT_BOOL(v, 4, printerror, false); SQ_OPT_BOOL(v, 5, show_warnings, false); SQInteger top = sq_gettop(self); SQRESULT result = SQ_ERROR; sq_pushroottable(self); //important always push the root table, because sqstd_dofile will try to do a sq_push(v, -2) if(sqstd_dofile(self, file_name, retval, printerror, show_warnings) >= 0) { if(retval) { if(copy_values_between_vms(v, self, 1, sq_gettop(self)) == SQ_OK) result = 1; } else result = SQ_OK; } else sq_throwerror(v, sq_getlasterror_str(self)); sq_settop(self, top); return result; }
/** * load a JS file into context */ static int sqlang_load_file(HSQUIRRELVM J, const char *filename) { if(!SQ_SUCCEEDED(sqstd_dofile(J, _SC(filename), 0, 1))) { /* prints syntax errors if any */ LM_ERR("failed to load file: %s\n", filename); return -1; } LM_DBG("loaded file: %s\n", filename); return 0; #if 0 FILE *f; size_t len; #define SQLANG_SCRIPT_MAX_SIZE 128*1024 char buf[SQLANG_SCRIPT_MAX_SIZE]; f = fopen(filename, "rb"); if (f) { len = fread((void *) buf, 1, sizeof(buf)-1, f); fclose(f); if(len>0) { buf[len] = '\0'; if(!SQ_SUCCEEDED(sq_compilebuffer(J, buf, len, _SC(filename), SQTrue))) { LM_ERR("failed to compile: %s\n", filename); return -1; } } else { LM_ERR("empty content in %s\n", filename); return -1; } } else { LM_ERR("cannot open file: %s\n", filename); return -1; } return 0; #endif }
void SqWrap::DoFile(const SQChar * fn) { sq_pushroottable(vm); sqstd_dofile(vm, fn, SQFalse, SQTrue); }
CResourceScript::CResourceScript ( CString strFile, int ScriptType, CResource *pResource ) { // Warp some varibles. m_pResource = pResource; m_iScriptType = ScriptType; // Format script localization. m_strFile.Format("%s\\%s\\%s", m_pResource->GetDirectory().Get(), m_pResource->GetName().Get(), strFile.Get()); // Check if file exists. if(!Exists(m_strFile.Get())) { CLog::Printf( "[Resources] Script %s not found!", m_strFile.Get() ); return; } // Check script type - default server. if ( ScriptType == SCRIPT_CLIENT ) { /* TODO: - Warp to code WebServ, - Create class for client resources, - .. */ } else { // Create root stack for script. m_pVM = sq_open(1024); //Register error and print functions. sqstd_seterrorhandlers(m_pVM); sq_setprintfunc(m_pVM, PrintFunction, ErrorFunction); sq_setcompilererrorhandler(m_pVM, CompilerErrorFunction); // Push root vm table. sq_pushroottable(m_pVM); // Register basic systems. sqstd_register_systemlib(m_pVM); sqstd_register_iolib(m_pVM); sqstd_register_bloblib(m_pVM); sqstd_register_mathlib(m_pVM); sqstd_register_stringlib(m_pVM); // Register Squirrel Classes m_pResource->RegisterClass(this); // Register all functions. // Event functions. CEventNatives::Register(this); // Funkcje gracza. CPlayerNatives::Register(this); if ( SQ_FAILED ( sqstd_dofile(m_pVM, m_strFile.Get(), SQFalse, SQTrue) ) ) { // cannot compile script file. return; } // Define basic varibles. CSquirrelArguments pArgs; pArgs.push(MAX_PLAYERS); RegisterVarible ( "MAX_PLAYERS", &pArgs ); pArgs.clear(); } }
int main(int argc, char *argv[]) { if(argc < 2){ scprintf(_SC("SQDBG error : no file specified")); return -1; } // RVF + int debuggerPort = 0; for (int i = 1; i < argc; i++) { const char* arg = argv[i]; if (!strncmp(arg, "-d", 2)) debuggerPort = std::atoi(arg + 2); } if (!debuggerPort) { scprintf(_SC("SQDBG error : Debugger port not specified. Use the -d<PORT> parameter")); return EXIT_FAILURE; } // RVF - HSQUIRRELVM v = sq_open(1024); sqstd_seterrorhandlers(v); //!! INITIALIZES THE DEBUGGER ON THE TCP PORT 1234 //!! ENABLES AUTOUPDATE HSQREMOTEDBG rdbg = sq_rdbg_init(v,debuggerPort,SQTrue); if(rdbg) { //!! ENABLES DEBUG INFO GENERATION(for the compiler) sq_enabledebuginfo(v,SQTrue); sq_setprintfunc(v,printfunc,errorfunc); //!! SUSPENDS THE APP UNTIL THE DEBUGGER CLIENT CONNECTS if(SQ_SUCCEEDED(sq_rdbg_waitforconnections(rdbg))) { scprintf(_SC("connected\n")); const SQChar *fname=NULL; #ifdef _UNICODE SQChar sTemp[256]; mbstowcs(sTemp,argv[argc-1],(int)strlen(argv[1])+1); fname=sTemp; #else fname=argv[argc-1]; #endif //!!REGISTERS STANDARDS LIBS sq_pushroottable(v); sqstd_register_bloblib(v); sqstd_register_iolib(v); sqstd_register_systemlib(v); sqstd_register_mathlib(v); sqstd_register_stringlib(v); //!!EXECUTE A SCTIPT if(SQ_FAILED(sqstd_dofile(v,fname,SQFalse,SQTrue))) { PrintError(v); _getch(); } } //!! CLEANUP sq_rdbg_shutdown(rdbg); } else { PrintError(v); } sq_close(v); return 0; }
//<<FIXME>> this func is a mess int getargs(HSQUIRRELVM v,int argc, char* argv[]) { int i; int compiles_only = 0; static SQChar temp[500]; const SQChar *ret=NULL; char * output = NULL; int lineinfo=0; int endian=0; const char *precompile = NULL; if(argc>1) { int arg=1,exitloop=0; while(arg < argc && !exitloop) { if(argv[arg][0]=='-') { switch(argv[arg][1]) { case 'd': //DEBUG(debug infos) sq_enabledebuginfo(v,1); break; case 'c': compiles_only = 1; break; case 'o': if(arg < argc) { arg++; output = argv[arg]; } break; case 'e': if(arg < argc) { arg++; endian = atoi(argv[arg]); } break; case 'v': PrintVersionInfos(); return _DONE; case 'h': PrintVersionInfos(); PrintUsage(); return _DONE; case 'p': if (arg < argc) { arg++; precompile = argv[arg]; } break; default: PrintVersionInfos(); scprintf(_SC("unknown prameter '-%c'\n"),argv[arg][1]); PrintUsage(); return _ERROR; } }else break; arg++; } // precompile header if (precompile) { const SQChar *a; #ifdef SQUNICODE int alen=(int)strlen(precompile); a=sq_getscratchpad(v,(int)(alen*sizeof(SQChar))); mbstowcs(sq_getscratchpad(v,-1),precompile,alen); sq_getscratchpad(v,-1)[alen] = _SC('\0'); #else a=precompile; #endif if(SQ_FAILED(sqstd_dofile(v,a,SQFalse,SQTrue))) { const SQChar *err; sq_getlasterror(v); if(SQ_SUCCEEDED(sq_getstring(v,-1,&err))) { scprintf(_SC("Error [%s]\n"),err); return _ERROR; } } } // src file if(arg<argc) { const SQChar *filename=NULL; #ifdef SQUNICODE mbstowcs(temp,argv[arg],strlen(argv[arg])); filename=temp; #else filename=argv[arg]; #endif arg++; sq_pushroottable(v); sq_pushstring(v,_SC("ARGS"),-1); sq_newarray(v,0); for(i=arg;i<argc;i++) { const SQChar *a; #ifdef SQUNICODE int alen=(int)strlen(argv[i]); a=sq_getscratchpad(v,(int)(alen*sizeof(SQChar))); mbstowcs(sq_getscratchpad(v,-1),argv[i],alen); sq_getscratchpad(v,-1)[alen] = _SC('\0'); #else a=argv[i]; #endif sq_pushstring(v,a,-1); sq_arrayappend(v,-2); } sq_createslot(v,-3); sq_pop(v,1); if(compiles_only) { if(SQ_SUCCEEDED(sqstd_loadfile(v,filename,SQTrue))){ SQChar *outfile = _SC("out.cnut"); if(output) { #ifdef SQUNICODE int len = (int)(strlen(output)+1); mbstowcs(sq_getscratchpad(v,len*sizeof(SQChar)),output,len); outfile = sq_getscratchpad(v,-1); #else outfile = output; #endif } if(SQ_SUCCEEDED(sqstd_writeclosuretofile(v,outfile,endian))) return _DONE; } } else { if(SQ_SUCCEEDED(sqstd_dofile(v,filename,SQFalse,SQTrue))) { return _DONE; } } //if this point is reached an error occured { const SQChar *err; sq_getlasterror(v); if(SQ_SUCCEEDED(sq_getstring(v,-1,&err))) { scprintf(_SC("Error [%s]\n"),err); return _ERROR; } } } } return _INTERACTIVE; }
int Sq_DoFile(HSQUIRRELVM VM, const char *File) { return sqstd_dofile(VM, _SC(File), SQFalse, SQTrue); }