1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 15:29:55 +00:00

Don't assume execution of an internal Lua script can't fail

This commit is contained in:
Evil Eye 2024-06-22 11:26:32 +02:00
parent ca3f89045c
commit 5b82c7a95d
2 changed files with 4 additions and 3 deletions

View file

@ -116,8 +116,9 @@ namespace LuaUtil
static void disableProfiler() { sProfilerEnabled = false; } static void disableProfiler() { sProfilerEnabled = false; }
static bool isProfilerEnabled() { return sProfilerEnabled; } static bool isProfilerEnabled() { return sProfilerEnabled; }
private:
static sol::protected_function_result throwIfError(sol::protected_function_result&&); static sol::protected_function_result throwIfError(sol::protected_function_result&&);
private:
template <typename... Args> template <typename... Args>
friend sol::protected_function_result call(const sol::protected_function& fn, Args&&... args); friend sol::protected_function_result call(const sol::protected_function& fn, Args&&... args);
template <typename... Args> template <typename... Args>

View file

@ -5,9 +5,9 @@ namespace LuaUi
{ {
sol::protected_function loadContentConstructor(LuaUtil::LuaState* state) sol::protected_function loadContentConstructor(LuaUtil::LuaState* state)
{ {
sol::function loader = state->loadInternalLib("content"); sol::protected_function loader = state->loadInternalLib("content");
sol::set_environment(state->newInternalLibEnvironment(), loader); sol::set_environment(state->newInternalLibEnvironment(), loader);
sol::table metatable = loader().get<sol::table>(); sol::table metatable = LuaUtil::LuaState::throwIfError(loader()).get<sol::table>();
if (metatable["new"].get_type() != sol::type::function) if (metatable["new"].get_type() != sol::type::function)
throw std::logic_error("Expected function"); throw std::logic_error("Expected function");
return metatable["new"].get<sol::protected_function>(); return metatable["new"].get<sol::protected_function>();