Use LuaUtil::cast for casting sol::object to prevent crashing on type mismatch in Lua scripts.

This commit is contained in:
Petr Mikheev 2023-04-25 22:11:04 +02:00
parent 61578ca39b
commit c362b2efa6
12 changed files with 48 additions and 46 deletions

View file

@ -85,7 +85,7 @@ namespace LuaUtil
if (values)
{
for (const auto& [k, v] : *values)
mValues[k.as<std::string>()] = Value(v);
mValues[cast<std::string>(k)] = Value(v);
}
if (mStorage->mListener)
mStorage->mListener->sectionReplaced(mSectionName, values);
@ -166,9 +166,9 @@ namespace LuaUtil
sol::table data = deserialize(mLua, serializedData);
for (const auto& [sectionName, sectionTable] : data)
{
const std::shared_ptr<Section>& section = getSection(sectionName.as<std::string_view>());
for (const auto& [key, value] : sol::table(sectionTable))
section->set(key.as<std::string_view>(), value);
const std::shared_ptr<Section>& section = getSection(cast<std::string_view>(sectionName));
for (const auto& [key, value] : cast<sol::table>(sectionTable))
section->set(cast<std::string_view>(key), value);
}
}
catch (std::exception& e)