| 105 | } |
| 106 | |
| 107 | bool 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 |
no test coverage detected