LuaYard/LuaVM.h

35 lines
528 B
C
Raw Normal View History

2019-08-06 20:36:04 +08:00
#pragma once
#include "lua/lua.hpp"
class LuaVM
{
public:
LuaVM() {
_L = luaL_newstate();
luaL_openlibs(_L);
_managed = true;
}
LuaVM(lua_State* L, bool managed=false) {
_L = L;
_managed = managed;
}
/// NonMoveable,NonCopyable
LuaVM(const LuaVM&) = delete;
LuaVM& operator = (const LuaVM&) = delete;
LuaVM(LuaVM&&) = delete;
LuaVM& operator = (LuaVM&&) = delete;
~LuaVM() {
if (_managed) {
lua_close(_L);
}
}
operator lua_State* () {
return _L;
}
private:
lua_State* _L;
bool _managed;
};