void SQDbgServer::SerializeState() { sq_pushnull(_v); sq_setdebughook(_v); sq_pushnull(_v); sq_seterrorhandler(_v); const SQChar *sz; sq_pushobject(_v,_serializefunc); sq_pushobject(_v,_debugroot); sq_pushstring(_v,_SC("watches"),-1); sq_newtable(_v); for(WatchSetItor i=_watches.begin(); i!=_watches.end(); ++i) { sq_pushinteger(_v,i->_id); sq_pushstring(_v,i->_exp.c_str(),(int)i->_exp.length()); sq_createslot(_v,-3); } sq_rawset(_v,-3); if(SQ_SUCCEEDED(sq_call(_v,1,SQTrue,SQTrue))){ if(SQ_SUCCEEDED(sqstd_getblob(_v,-1,(SQUserPointer*)&sz))) SendChunk(sz); } sq_pop(_v,2); SetErrorHandlers(); }
void SqEnv::_init(size_t sz) { // AutoLock a(&_m); __vm = sq_open(sz); _vm= &__vm; assert( *_vm ); Sqrat::DefaultVM::Set(*_vm); sq_setprintfunc(*_vm, SqEnv::print_func, SqEnv::print_func); sq_newclosure(*_vm, SqEnv::error_handler,0); sq_seterrorhandler(*_vm); //sq sq_pushroottable(*_vm); sqstd_register_iolib(*_vm); sqstd_register_bloblib(*_vm); sqstd_register_mathlib(*_vm); sqstd_register_stringlib(*_vm); sqstd_register_systemlib(*_vm); sqstd_seterrorhandlers(*_vm); sqstd_printcallstack(*_vm); // setnativedebughook(_vmsys,debug_hook); sq_notifyallexceptions(*_vm, true); }
void SQDbgServer::SetErrorHandlers() { sq_pushregistrytable(_v); sq_pushstring(_v,SQDBG_DEBUG_HOOK,-1); sq_rawget(_v,-2); sq_setdebughook(_v); sq_pushstring(_v,SQDBG_ERROR_HANDLER,-1); sq_rawget(_v,-2); sq_seterrorhandler(_v); sq_pop(_v,1); }
bool CSquirrel::Load(String strName, String strPath) { // Check if the script exists if(!SharedUtility::Exists(strPath.Get())) return false; // Set the script name m_strName = strName; // Set the script path m_strPath = strPath; // Create a squirrel VM with an initial stack size of 1024 bytes (stack will resize as needed) m_pVM = sq_open(1024); // Register the default error handlers sqstd_seterrorhandlers(m_pVM); // Set the print function and error function sq_setprintfunc(m_pVM, PrintFunction, PrintFunction); // Set the compiler error function sq_setcompilererrorhandler(m_pVM, CompilerErrorFunction); // Set our error handler sq_newclosure(m_pVM, PrintErrorFunction, 0); sq_seterrorhandler(m_pVM); // Push the root table onto the stack sq_pushroottable(m_pVM); #ifdef _SERVER // Register the input/output library sqstd_register_iolib(m_pVM); #endif // Register the blob library sqstd_register_bloblib(m_pVM); // Register the math library sqstd_register_mathlib(m_pVM); // Register the string library sqstd_register_stringlib(m_pVM); return true; }
void sqstd_seterrorhandlers(HSQUIRRELVM v) { sq_setcompilererrorhandler(v,_sqstd_compiler_error); sq_newclosure(v,_sqstd_aux_printerror,0); sq_seterrorhandler(v); // additional functions sq_pushroottable(v); sq_pushstring(v, _SC("printCallStack"), -1); sq_newclosure(v, printCallStack, 0); sq_createslot(v, -3); sq_pushstring(v, _SC("notifyAllExceptions"), -1); sq_newclosure(v, notifyAllExceptions, 0); sq_setparamscheck(v, 2, _SC(".n|b")); sq_createslot(v, -3); sq_pop(v,1); }
void Context::initialize() { sq_setforeignptr(vm_, this); sq_setprintfunc(vm_, Detail::print, Detail::printError); sq_pushroottable(vm_); sqstd_register_mathlib(vm_); sqstd_register_stringlib(vm_); sqstd_register_bloblib(vm_); sq_setcompilererrorhandler(vm_, Detail::handleCompilerError); sq_newclosure(vm_, Detail::handleError, 0); sq_seterrorhandler(vm_); sq_pop(vm_, 1); Table::create(*this, _SC("__sqrew_classes"), TableDomain::Registry); }
Squirrel::Squirrel() { this->vm = sq_open(1024); this->print_func = NULL; this->global_pointer = NULL; this->crashed = false; /* Handle compile-errors ourself, so we can display it nicely */ sq_setcompilererrorhandler(this->vm, &Squirrel::CompileError); sq_notifyallexceptions(this->vm, SQTrue); /* Set a good print-function */ sq_setprintfunc(this->vm, &Squirrel::PrintFunc); /* Handle runtime-errors ourself, so we can display it nicely */ sq_newclosure(this->vm, &Squirrel::_RunError, 0); sq_seterrorhandler(this->vm); /* Set the foreigh pointer, so we can always find this instance from within the VM */ sq_setforeignptr(this->vm, this); sq_pushroottable(this->vm); squirrel_register_global_std(this); }
void SQDbgServer::SerializeState(HSQUIRRELVM v) { sq_pushnull(v); sq_setdebughook(v); sq_pushnull(v); sq_seterrorhandler(v); sq_pushobject(v, _serializefunc); sq_pushobject(v, _debugroot); sq_pushstring(v, _SC("watches"), -1); sq_newtable(v); for (WatchSetItor i = _watches.begin(); i != _watches.end(); ++i) { sq_pushinteger(v, i->_id); sq_pushstring(v, i->_exp.c_str(), (SQInteger) i->_exp.length()); sq_createslot(v, -3); } sq_rawset(v, -3); if (SQ_SUCCEEDED(sq_call(v, 1, SQTrue, SQFalse))) { //if(SQ_SUCCEEDED(sqstd_getblob(v,-1,(SQUserPointer*)&sz))) //SendChunk(sz); } sq_pop(v, 2); SetErrorHandlers(v); }
static SQInteger base_seterrorhandler(HSQUIRRELVM v) { sq_seterrorhandler(v); return 0; }
void sqstd_seterrorhandlers(HSQUIRRELVM v) { sq_setcompilererrorhandler(v,_sqstd_compiler_error); sq_newclosure(v,_sqstd_aux_printerror,0); sq_seterrorhandler(v); }