aboutsummaryrefslogtreecommitdiff
path: root/src/lua/common/je_lua.cpp
diff options
context:
space:
mode:
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