summaryrefslogtreecommitdiff
path: root/Source/3rdParty/Luax/luax_runtime.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-03-12 23:08:31 +0800
committerchai <chaifix@163.com>2019-03-12 23:08:31 +0800
commit6016ece202eef94ed76bd20d4f7879ccc71cc2e6 (patch)
treeda0d0be011ee24489174bde1ec1c436ce7aaa1b2 /Source/3rdParty/Luax/luax_runtime.cpp
parent9eba034f5c2ffd49f33d38c283b24230f9e362e0 (diff)
*luax
Diffstat (limited to 'Source/3rdParty/Luax/luax_runtime.cpp')
-rw-r--r--Source/3rdParty/Luax/luax_runtime.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/Source/3rdParty/Luax/luax_runtime.cpp b/Source/3rdParty/Luax/luax_runtime.cpp
index e69de29..1c5becb 100644
--- a/Source/3rdParty/Luax/luax_runtime.cpp
+++ b/Source/3rdParty/Luax/luax_runtime.cpp
@@ -0,0 +1,97 @@
+#ifndef __LUAX_RUNTIME_H_
+#define __LUAX_RUNTIME_H_
+
+#include "luax_runtime.h"
+
+using namespace std;
+
+namespace Luax
+{
+
+ Context::Context(lua_State* L)
+ : state(L)
+ {
+ strongRefTable.Init(state, "LUAX_STRONGREF_TABLE");
+ weakRefTable.Init(state, "LUAX_WEAKREF_TABLE", "v");
+ }
+
+ Context::~Context()
+ {
+ }
+
+ //--------------------------------------------------------------------------------------------------------------
+
+ LuaxRuntime* LuaxRuntime::mRuntime = nullptr;
+
+ LuaxRuntime::LuaxRuntime() {};
+ LuaxRuntime::~LuaxRuntime() {};
+
+ LuaxRuntime& LuaxRuntime::Get()
+ {
+ if (mRuntime == nullptr)
+ mRuntime = new LuaxRuntime();
+
+ return *mRuntime;
+ }
+
+ lua_State* LuaxRuntime::Open()
+ {
+ lua_State* L = lua_open();
+ assert(L);
+ mContexts.insert(pair<lua_State*, Context>(L, Context(L)));
+ return L;
+ }
+
+ void LuaxRuntime::Close(lua_State* L)
+ {
+ map<lua_State*, Context>::iterator it = mContexts.find(L);
+ if (it != mContexts.end())
+ {
+ lua_close(it->second.state);
+ mContexts.erase(it);
+ }
+ }
+
+ bool LuaxRuntime::HasLuaxState(lua_State* L)
+ {
+ map<lua_State*, Context>::iterator it = mContexts.find(L);
+ return it != mContexts.end();
+ }
+
+ LuaxState& LuaxRuntime::GetLuaxState(lua_State* L)
+ {
+ map<lua_State*, Context>::iterator it = mContexts.find(L);
+ if (it != mContexts.end())
+ {
+ return it->second.state;
+ }
+ }
+
+ LuaxRefTable& LuaxRuntime::GetStrongRefTable(lua_State* L)
+ {
+ map<lua_State*, Context>::iterator it = mContexts.find(L);
+ if (it != mContexts.end())
+ {
+ return it->second.strongRefTable;
+ }
+ }
+
+ LuaxRefTable& LuaxRuntime::GetWeaksRefTable(lua_State* L)
+ {
+ map<lua_State*, Context>::iterator it = mContexts.find(L);
+ if (it != mContexts.end())
+ {
+ return it->second.weakRefTable;
+ }
+ }
+
+ Context& LuaxRuntime::operator[](lua_State* L)
+ {
+ map<lua_State*, Context>::iterator it = mContexts.find(L);
+ assert(it != mContexts.end());
+ return it->second;
+ }
+
+}
+
+#endif \ No newline at end of file