Fix crash when passing a non-callback table to a callback argument

BindlessTest
uramer 11 months ago
parent c889026b71
commit 35448bf0fe

@ -24,7 +24,11 @@ namespace LuaUtil
Callback Callback::fromLua(const sol::table& t) Callback Callback::fromLua(const sol::table& t)
{ {
return Callback{ t.raw_get<sol::main_protected_function>(1), t.raw_get<AsyncPackageId>(2).mHiddenData }; const sol::object& function = t.get_or(1, sol::nil);
const sol::object& asyncPackageId = t.get_or(2, sol::nil);
if (!function.is<sol::main_protected_function>() || !asyncPackageId.is<AsyncPackageId>())
throw std::domain_error("Expected an async:callback, received a table");
return Callback{ function.as<sol::main_protected_function>(), asyncPackageId.as<AsyncPackageId>().mHiddenData };
} }
bool Callback::isLuaCallback(const sol::object& t) bool Callback::isLuaCallback(const sol::object& t)

Loading…
Cancel
Save