diff options
author | chai <chaifix@163.com> | 2021-10-18 19:56:41 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-18 19:56:41 +0800 |
commit | 45328cbadd8a946c19a77301f218efbf650e2f28 (patch) | |
tree | 8ec4f3a9737b2cbb9744f8347a56783743be2a4c /Runtime/LuaBind/LuaBindVM.cpp | |
parent | b5702ece4c2cf751c252e76fb885a7ec41ccabe8 (diff) |
*misc
Diffstat (limited to 'Runtime/LuaBind/LuaBindVM.cpp')
-rw-r--r-- | Runtime/LuaBind/LuaBindVM.cpp | 82 |
1 files changed, 0 insertions, 82 deletions
diff --git a/Runtime/LuaBind/LuaBindVM.cpp b/Runtime/LuaBind/LuaBindVM.cpp deleted file mode 100644 index 268a5ed..0000000 --- a/Runtime/LuaBind/LuaBindVM.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include "LuaBindInternal.h" -#include "LuaBindVM.h" - -namespace LuaBind -{ - - VM::VMap VM::VMs; // 通过线程查找虚拟机,为了方便 - - VM* VM::TryGetVM(global_State* gState) - { - auto it = VMs.find(gState); - if (it != VMs.end()) - return it->second; - else - return nullptr; - } - - VM* VM::TryGetVM(lua_State* state) - { - return TryGetVM(G(state)); - } - - VM::VM() - : mStrongRefTable() - , mWeakRefTable() - { - mMainThread = luaL_newstate(); - assert(mMainThread); - mGlobalState = G(mMainThread); - - VMs.insert(std::pair<global_State*, VM*>(mGlobalState, this)); - } - - VM::~VM() - { - VMs.erase(mGlobalState); - lua_close(mMainThread); - } - - // 初始化context - void VM::Setup() - { - LUA_BIND_STATE(mMainThread); - - mStrongRefTable.Init(state, "GAMELAB_UNIVERSAL_STRONG_REFERENCE_TABLE"); - mWeakRefTable.Init(state, "GAMELAB_UNIVERSAL_WEAK_REFERENCE_TABLE", "v"); - } - - lua_State* VM::CreateThread() - { - lua_State* thread = lua_newthread(mMainThread); - assert(thread); - return thread; - } - - lua_State* VM::GetMainThread() - { - return mMainThread; - } - - State VM::GetMainState() - { - return mMainThread; - } - - RefTable& VM::GetStrongRefTable() - { - return mStrongRefTable; - } - - RefTable& VM::GetWeakRefTable() - { - return mWeakRefTable; - } - - void VM::OpenLibs() - { - assert(mMainThread); - luaL_openlibs(mMainThread); - } - -}
\ No newline at end of file |