MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / runScript

Method runScript

game/state/luagamestate.cpp:107–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105}
106
107bool LuaGameState::runScript(const UString &scriptPath)
108{
109 LogInfo("Running script \"%s\"", scriptPath);
110 auto scriptFile = fw().data->fs.open(scriptPath);
111 if (!scriptFile)
112 {
113 LogWarning("Failed to open script \"%s\"", scriptPath);
114 return false;
115 }
116
117 const auto &fullPath = scriptFile.systemPath();
118 LogInfo("Loading script from \"%s\"", fullPath);
119
120 bool ret = true;
121 pushLuaDebugTraceback(L);
122 // this is only true if loadfile or pcall raised an error
123 if (luaL_loadfile(L, fullPath.c_str()) || lua_pcall(L, 0, 0, -2))
124 {
125 handleLuaError(L);
126 LogWarning("Script \"%s\" failed", scriptPath);
127 ret = false;
128 }
129 lua_pop(L, 1); // pop debug.traceback function
130 LogInfo("Script run %s", ret ? "success" : "fail");
131 return ret;
132}
133
134} // namespace OpenApoc

Callers 1

loadModsMethod · 0.80

Calls 3

pushLuaDebugTracebackFunction · 0.85
handleLuaErrorFunction · 0.85
openMethod · 0.80

Tested by

no test coverage detected