aboutsummaryrefslogtreecommitdiff
path: root/src/lua/common/je_lua.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-11-23 21:27:56 +0800
committerchai <chaifix@163.com>2018-11-23 21:27:56 +0800
commit37f9824273fc3233f84bcff4ecfe1132dad74185 (patch)
tree65afadbfa967cdb911a1692a805713f3643530b2 /src/lua/common/je_lua.cpp
parent9b04526b50140871c5cdd85b7c42f07a7685e971 (diff)
*更新绑定
Diffstat (limited to 'src/lua/common/je_lua.cpp')
-rw-r--r--src/lua/common/je_lua.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/lua/common/je_lua.cpp b/src/lua/common/je_lua.cpp
index ad3f756..d53898d 100644
--- a/src/lua/common/je_lua.cpp
+++ b/src/lua/common/je_lua.cpp
@@ -115,5 +115,62 @@ namespace JinEngine
return 1;
}
+ void luax_getreference(lua_State* L, SharedBase* shared)
+ {
+ luax_getreferencestable(L);
+ luax_pushlightuserdata(L, shared);
+ luax_gettable(L, -2);
+ luax_remove(L, -2);
+ }
+
+ bool luax_addreference(lua_State* L, SharedBase* shared, SharedBase* dep)
+ {
+ luax_getreference(L, shared);
+ // If no dependencies table, add one.
+ if (luax_isnil(L, -1))
+ {
+ luax_pop(L, 1);
+ luax_getreferencestable(L);
+ luax_newtable(L);
+ luax_pushlightuserdata(L, shared);
+ luax_pushvalue(L, -2);
+ luax_settable(L, -4);
+ luax_remove(L, -2); // Remove references table.
+ }
+ luax_pushlightuserdata(L, dep);
+ luax_getobject(L, dep);
+ if (luax_isnil(L, -1))
+ {
+ luax_pop(L, 3); // Pop nil, dep, reftbl
+ return false;
+ }
+ luax_settable(L, -3);
+ luax_pop(L, 1);
+ return true;
+ }
+
+ void luax_removereference(lua_State* L, SharedBase* shared)
+ {
+ luax_getreferencestable(L);
+ luax_pushlightuserdata(L, shared);
+ luax_pushnil(L);
+ luax_settable(L, -3);
+ luax_pop(L, 1);
+ }
+
+ void luax_removereference(lua_State* L, SharedBase* shared, SharedBase* dep)
+ {
+ luax_getreference(L, shared);
+ if (luax_isnil(L, -1))
+ {
+ luax_pop(L, 1);
+ return;
+ }
+ luax_pushlightuserdata(L, dep);
+ luax_pushnil(L);
+ luax_settable(L, -3);
+ luax_pop(L, 1);
+ }
+
}
} \ No newline at end of file