1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-12-24 07:23:08 +00:00

Merge branch 'verysafeget' into 'master'

Don't accept table like objects in getFieldOrNil

Closes #8840

See merge request OpenMW/openmw!5035
This commit is contained in:
Alexei Kotov 2025-12-10 21:19:22 +03:00
commit 51e5328596
2 changed files with 4 additions and 4 deletions

View file

@ -258,7 +258,7 @@ return {
TEST_F(LuaStateTest, SafeIndexMetamethod)
{
const VFS::Path::Normalized path("metaIndexError.lua");
sol::table t = mLua.runInNewSandbox(path);
sol::lua_table t = mLua.runInNewSandbox(path);
// without safe get we crash here
EXPECT_ERROR(LuaUtil::safeGet(t, "any key"), "meta index error");
}

View file

@ -286,7 +286,7 @@ namespace LuaUtil
// work around for a (likely) sol3 bug
// when the index meta method throws, simply calling table.get crashes instead of re-throwing the error
template <class Key>
sol::object safeGet(const sol::table& table, const Key& key)
sol::object safeGet(const sol::lua_table& table, const Key& key)
{
auto index = table.traverse_raw_get<sol::optional<sol::main_protected_function>>(
sol::metatable_key, sol::meta_function::index);
@ -306,9 +306,9 @@ namespace LuaUtil
template <class... Str>
sol::object getFieldOrNil(const sol::object& table, std::string_view first, const Str&... str)
{
if (!table.is<sol::table>())
if (!table.is<sol::lua_table>())
return sol::nil;
sol::object value = safeGet(table.as<sol::table>(), first);
sol::object value = safeGet(table.as<sol::lua_table>(), first);
if constexpr (sizeof...(str) == 0)
return value;
else