From 157530b8b6e11efc5573d5a0db8987a440197aa1 Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 29 Mar 2019 22:28:40 +0800 Subject: *misc --- source/3rd-party/Luax/luax_vm.h | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'source/3rd-party/Luax/luax_vm.h') diff --git a/source/3rd-party/Luax/luax_vm.h b/source/3rd-party/Luax/luax_vm.h index 9039a04..1bac71e 100644 --- a/source/3rd-party/Luax/luax_vm.h +++ b/source/3rd-party/Luax/luax_vm.h @@ -7,6 +7,7 @@ #include "luax_ref.h" #include "luax_config.h" #include "luax_state.h" +#include "luax_globalstate.h" namespace Luax { @@ -17,38 +18,41 @@ namespace Luax class LuaxVM { public: + + /// + /// 根据global_State拿到虚拟机。 + /// + static LuaxVM* TryGetVM(global_State* gState); + static LuaxVM* TryGetVM(lua_State* state); + LuaxVM(); ~LuaxVM(); + /// + /// 创建虚拟机后,需要手动调用Setup函数,初始化一些虚拟机状态。 + /// void Setup(); - lua_State* CreateThread(); lua_State* GetMainThread(); - - int GetThreadCount(); + lua_State* CreateThread(); LuaxRefTable& GetStrongRefTable(); LuaxRefTable& GetWeakRefTable(); - bool HasThread(lua_State* L); - - static LuaxVM* TryGetVM(lua_State* L); - - typedef std::map ThreadMap; - private: - static ThreadMap threadMap; // 通过线程查找虚拟机,为了方便 + typedef std::map VMap; - LuaxRefTable mStrongRefTable; // _LUAX_STRONGREF_TABLE - LuaxRefTable mWeakRefTable; // _LUAX_WEAKREF_TABLE + static VMap VMs; // 通过global_State索引虚拟机,为了方便 - lua_State* mMainThread; // 主线程 + LuaxRefTable mStrongRefTable; // _LUAX_STRONGREF_TABLE + LuaxRefTable mWeakRefTable; // _LUAX_WEAKREF_TABLE - std::unordered_set mThreads; // 所有线程 + global_State* mGlobalState; // 虚拟机的global_State,由当前虚拟机的所有线程共享 + lua_State* mMainThread; // 主线程 #if LUAX_PROFILER - size_t mObjectCount; // 统计所有在此虚拟机中创建的实例 + size_t mObjectCount; // 统计所有在此虚拟机中创建的实例 #endif }; -- cgit v1.1-26-g67d0