From 6016ece202eef94ed76bd20d4f7879ccc71cc2e6 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 12 Mar 2019 23:08:31 +0800 Subject: *luax --- Source/3rdParty/Luax/luax_runtime.h | 64 ++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) (limited to 'Source/3rdParty/Luax/luax_runtime.h') diff --git a/Source/3rdParty/Luax/luax_runtime.h b/Source/3rdParty/Luax/luax_runtime.h index 94d8ecc..2414c2e 100644 --- a/Source/3rdParty/Luax/luax_runtime.h +++ b/Source/3rdParty/Luax/luax_runtime.h @@ -1,13 +1,69 @@ #ifndef __LUAX_RUNTIME_H__ #define __LUAX_RUNTIME_H__ -namespace Luax +#include + +#include "luax_config.h" +#include "luax_state.h" + +namespace Luax { - enum RegisterIndex + /// + /// 单个lua_state相关的context。是一系列代理的集合,拷贝也没关系,主要是为了节约内存。 + /// + class Context { - LUAX_OBJECT_INDEX = 1, - LUAX_OBJECT_MODULE = 2, + public: + Context(lua_State* L); + ~Context(); + + LuaxState state; // lua state + LuaxRefTable strongRefTable; // strong ref table + LuaxRefTable weakRefTable; // weak ref table + + size_t objectCount; // 统计所有在此state中创建的实例 + + }; + + /// + /// 统一管理程序所有的lua states。 + /// + class LuaxRuntime + { + public: + + static LuaxRuntime& Get(); + + /// + /// 创建一个新的lua_State并保存下来。返回的lua_State*是一个8\4字节的key。 + /// + lua_State* Open(); + + /// + /// 关闭lua_State并将其从runtime中删除。 + /// + void Close(lua_State* L); + + bool HasLuaxState(lua_State* L); + LuaxState& GetLuaxState(lua_State* L); + LuaxRefTable& GetStrongRefTable(lua_State* L); + LuaxRefTable& GetWeaksRefTable(lua_State* L); + + Context& operator[](lua_State* L); + + private: + + LuaxRuntime(); + ~LuaxRuntime(); + + static LuaxRuntime* mRuntime; + + /// + /// 从lua_state找到context + /// + std::map mContexts; + }; } -- cgit v1.1-26-g67d0