diff options
author | chai <chaifix@163.com> | 2021-10-17 23:05:01 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-17 23:05:01 +0800 |
commit | 7c8c68d79343d04be382334c15a73d079450857c (patch) | |
tree | 9aaacc042f0b7eeb4123c07dcc5f49c14fd8026c /Runtime/LuaBind/LuaBindVM.h | |
parent | 6e73ca6ada8a41692809dae5db89c8db0675ce1e (diff) |
*misc
Diffstat (limited to 'Runtime/LuaBind/LuaBindVM.h')
-rw-r--r-- | Runtime/LuaBind/LuaBindVM.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/Runtime/LuaBind/LuaBindVM.h b/Runtime/LuaBind/LuaBindVM.h new file mode 100644 index 0000000..3bfe899 --- /dev/null +++ b/Runtime/LuaBind/LuaBindVM.h @@ -0,0 +1,58 @@ +#ifndef __LUA_BIND_CONTEXT_H__ +#define __LUA_BIND_CONTEXT_H__ + +#include <map> +#include <unordered_set> + +#include "LuaBindRef.h" +#include "LuaBindConfig.h" +#include "LuaBindState.h" +#include "LuaBindGlobalState.h" + +namespace LuaBind +{ + + // 单个lua_state相关的context。是一系列代理的集合,拷贝也没关系,主要是为了节约内存。 + class VM + { + public: + + // 根据global_State拿到虚拟机。 + static VM* TryGetVM(global_State* gState); + static VM* TryGetVM(lua_State* state); + + VM(); + ~VM(); + + // 创建虚拟机后,需要手动调用Setup函数,初始化一些虚拟机状态。 + void Setup(); + void OpenLibs(); + + lua_State* GetMainThread(); + lua_State* CreateThread(); + State GetMainState(); + + RefTable& GetStrongRefTable(); + RefTable& GetWeakRefTable(); + + private: + + typedef std::map<global_State*, VM*> VMap; + + static VMap VMs; // 通过global_State索引虚拟机,为了方便 + + RefTable mStrongRefTable; // GAMELAB_UNIVERSAL_STRONG_REFERENCE_TABLE + RefTable mWeakRefTable; // GAMELAB_UNIVERSAL_WEAK_REFERENCE_TABLE + + global_State* mGlobalState; // 虚拟机的global_State,由当前虚拟机的所有线程共享 + lua_State* mMainThread; // 主线程 + +#if LUA_BIND_PROFILER + size_t mObjectCount; // 统计所有在此虚拟机中创建的实例 +#endif + + }; + +} + +#endif
\ No newline at end of file |