MCPcopy Create free account
hub / github.com/Norbyte/bg3se / LoadScript

Method LoadScript

BG3Extender/Lua/LuaBinding.cpp:589–619  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

587}
588
589std::optional<int> State::LoadScript(STDString const & script, STDString const & name, int globalsIdx)
590{
591 int top = lua_gettop(L);
592
593 /* Load the file containing the script we are going to run */
594 int status = luaL_loadbufferx(L, script.c_str(), script.size(), name.c_str(), "text");
595 if (status != LUA_OK) {
596 LuaError("Failed to parse script: " << lua_tostring(L, -1));
597 lua_pop(L, 1); /* pop error message from the stack */
598 return {};
599 }
600
601#if LUA_VERSION_NUM <= 501
602 if (globalsIdx != 0) {
603 lua_pushvalue(L, globalsIdx);
604 lua_setfenv(L, -2);
605 }
606#endif
607
608 /* Ask Lua to run our little script */
609 LifetimeStackPin _(L, lifetimeStack_);
610 ProfilerStackGuard _p(this);
611 status = CallWithTraceback(L, 0, LUA_MULTRET);
612 if (status != LUA_OK) {
613 LuaError("Failed to execute script: " << lua_tostring(L, -1));
614 lua_pop(L, 1); // pop error message from the stack
615 return {};
616 }
617
618 return lua_gettop(L) - top;
619}
620
621void State::OnGameSessionLoading()
622{

Callers 3

LuaLoadExternalFileMethod · 0.80
LuaLoadGameFileMethod · 0.80
LuaLoadBuiltinFileMethod · 0.80

Calls 2

CallWithTracebackFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected