35 lines
528 B
C
35 lines
528 B
C
|
#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;
|
||
|
};
|