LuaYard/LuaVM.h
2019-08-10 21:34:36 +08:00

38 lines
576 B
C++

#pragma once
#include "lua/lua.h"
#include "lua/lualib.h"
#include "lua/lauxlib.h"
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;
};