mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-28 21:07:59 +03:00
Use unique_ptr to handle lua state lifetime
This commit is contained in:
parent
87d77a6882
commit
f80283422f
5 changed files with 48 additions and 42 deletions
|
@ -1,8 +1,9 @@
|
|||
#include "luascripts.hpp"
|
||||
|
||||
#include "components/esm3/esmreader.hpp"
|
||||
#include "components/esm3/esmwriter.hpp"
|
||||
#include <components/esm3/esmreader.hpp>
|
||||
#include <components/esm3/esmwriter.hpp>
|
||||
|
||||
#include <components/lua/luastateptr.hpp>
|
||||
#include <components/lua/serialization.hpp>
|
||||
|
||||
// List of all records, that are related to Lua.
|
||||
|
@ -102,13 +103,16 @@ void ESM::LuaScriptsCfg::adjustRefNums(const ESMReader& esm)
|
|||
throw std::runtime_error("Incorrect contentFile index");
|
||||
};
|
||||
|
||||
lua_State* L = luaL_newstate();
|
||||
LuaUtil::LuaStatePtr state(luaL_newstate());
|
||||
if (state == nullptr)
|
||||
throw std::runtime_error("Failed to create Lua runtime");
|
||||
|
||||
LuaUtil::BasicSerializer serializer(adjustRefNumFn);
|
||||
|
||||
auto adjustLuaData = [&](std::string& data) {
|
||||
if (data.empty())
|
||||
return;
|
||||
sol::object luaData = LuaUtil::deserialize(L, data, &serializer);
|
||||
sol::object luaData = LuaUtil::deserialize(state.get(), data, &serializer);
|
||||
data = LuaUtil::serialize(luaData, &serializer);
|
||||
};
|
||||
|
||||
|
@ -123,7 +127,6 @@ void ESM::LuaScriptsCfg::adjustRefNums(const ESMReader& esm)
|
|||
refCfg.mRefnumContentFile = adjustRefNumFn(refCfg.mRefnumContentFile);
|
||||
}
|
||||
}
|
||||
lua_close(L);
|
||||
}
|
||||
|
||||
void ESM::LuaScriptsCfg::save(ESMWriter& esm) const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue