MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / LoadScript

Method LoadScript

src/script/squirrel.cpp:689–711  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

687}
688
689bool Squirrel::LoadScript(HSQUIRRELVM vm, const std::string &script, bool in_root)
690{
691 ScriptAllocatorScope alloc_scope(this);
692
693 /* Make sure we are always in the root-table */
694 if (in_root) sq_pushroottable(vm);
695
696 SQInteger ops_left = vm->_ops_till_suspend;
697 /* Load and run the script */
698 if (SQ_SUCCEEDED(LoadFile(vm, script, SQTrue))) {
699 sq_push(vm, -2);
700 if (SQ_SUCCEEDED(sq_call(vm, 1, SQFalse, SQTrue, 100000))) {
701 sq_pop(vm, 1);
702 /* After compiling the file we want to reset the amount of opcodes. */
703 vm->_ops_till_suspend = ops_left;
704 return true;
705 }
706 }
707
708 vm->_ops_till_suspend = ops_left;
709 Debug(misc, 0, "[squirrel] Failed to compile '{}'", script);
710 return false;
711}
712
713bool Squirrel::LoadScript(const std::string &script)
714{

Callers 5

requireMethod · 0.80
InitializeMethod · 0.80
AddFileMethod · 0.80
ImportMethod · 0.80

Calls 4

sq_pushroottableFunction · 0.85
sq_pushFunction · 0.85
sq_callFunction · 0.85
sq_popFunction · 0.85

Tested by

no test coverage detected