summaryrefslogtreecommitdiff
path: root/Runtime/Scripting/LuaBindVM.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-11-15 09:59:32 +0800
committerchai <chaifix@163.com>2020-11-15 09:59:32 +0800
commitd2e4b2839bc7ce874370ff4c52dcfdadf666ff52 (patch)
treeb83e34c2d66cf80b94af5c9a420b6c9c206c138c /Runtime/Scripting/LuaBindVM.h
parent64f89347883d519b202711a11d2ea175bd80be37 (diff)
+lua binding
Diffstat (limited to 'Runtime/Scripting/LuaBindVM.h')
-rw-r--r--Runtime/Scripting/LuaBindVM.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/Runtime/Scripting/LuaBindVM.h b/Runtime/Scripting/LuaBindVM.h
new file mode 100644
index 0000000..dcff44f
--- /dev/null
+++ b/Runtime/Scripting/LuaBindVM.h
@@ -0,0 +1,63 @@
+#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 LuaBindVM
+ {
+ public:
+
+ ///
+ /// 根据global_State拿到虚拟机。
+ ///
+ static LuaBindVM* TryGetVM(global_State* gState);
+ static LuaBindVM* TryGetVM(lua_State* state);
+
+ LuaBindVM();
+ ~LuaBindVM();
+
+ ///
+ /// 创建虚拟机后,需要手动调用Setup函数,初始化一些虚拟机状态。
+ ///
+ void Setup();
+
+ lua_State* GetMainThread();
+ lua_State* CreateThread();
+ LuaBindState GetMainState();
+
+ LuaBindRefTable& GetStrongRefTable();
+ LuaBindRefTable& GetWeakRefTable();
+
+ private:
+
+ typedef std::map<global_State*, LuaBindVM*> VMap;
+
+ static VMap VMs; // 通过global_State索引虚拟机,为了方便
+
+ LuaBindRefTable mStrongRefTable; // _LUA_BIND_STRONGREF_TABLE
+ LuaBindRefTable mWeakRefTable; // _LUA_BIND_WEAKREF_TABLE
+
+ global_State* mGlobalState; // 虚拟机的global_State,由当前虚拟机的所有线程共享
+ lua_State* mMainThread; // 主线程
+
+#if LUA_BIND_PROFILER
+ size_t mObjectCount; // 统计所有在此虚拟机中创建的实例
+#endif
+
+ };
+
+}
+
+#endif \ No newline at end of file