Use unique_ptr to handle lua state lifetime

This commit is contained in:
elsid 2025-04-18 13:32:11 +02:00
parent 87d77a6882
commit f80283422f
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
5 changed files with 48 additions and 42 deletions

View file

@ -0,0 +1,18 @@
#ifndef OPENMW_COMPONENTS_LUA_LUASTATEPTR_H
#define OPENMW_COMPONENTS_LUA_LUASTATEPTR_H
#include <sol/state.hpp>
#include <memory>
namespace LuaUtil
{
struct CloseLuaState
{
void operator()(lua_State* state) noexcept { lua_close(state); }
};
using LuaStatePtr = std::unique_ptr<lua_State, CloseLuaState>;
}
#endif