SquirrelScript *LoadAddon(const char *Path) { SquirrelScript *NewAddon = NULL; // check if the addon already exists const char *ScriptName = FilenameOnly(Path); if(!AllScripts) { NewAddon = (SquirrelScript*)calloc(1,sizeof(SquirrelScript)); AllScripts = NewAddon; } else { SquirrelScript *Find = AllScripts; while(Find->Next) { if(!strcasecmp(ScriptName, Find->Name)) // don't load same addon more than once return NULL; Find = Find->Next; } NewAddon = (SquirrelScript*)calloc(1,sizeof(SquirrelScript)); // all pointers NULL Find->Next = NewAddon; NewAddon->Prev = Find; } if(!NewAddon) return NULL; NewAddon->Script = Sq_Open(Path); strlcpy(NewAddon->Name, ScriptName, sizeof(NewAddon->Name)); sq_setforeignptr(NewAddon->Script, (SQUserPointer)NewAddon); return NewAddon; }
bool SquirrelThread::setForeignPtr(void* foreignPtr) { if (!m_thread) { return false; } sq_setforeignptr(m_thread, foreignPtr); return true; }
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); }