aboutsummaryrefslogtreecommitdiff
path: root/src/deep.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/deep.cpp')
-rw-r--r--src/deep.cpp26
1 files changed, 3 insertions, 23 deletions
diff --git a/src/deep.cpp b/src/deep.cpp
index 9474666..2f4f1ed 100644
--- a/src/deep.cpp
+++ b/src/deep.cpp
@@ -159,7 +159,7 @@ void DeepFactory::DeleteDeepObject(lua_State* L_, DeepPrelude* o_)
159 bool const isLastRef{ _p->refcount.fetch_sub(1, std::memory_order_relaxed) == 1 }; 159 bool const isLastRef{ _p->refcount.fetch_sub(1, std::memory_order_relaxed) == 1 };
160 160
161 if (isLastRef) { 161 if (isLastRef) {
162 // retrieve wrapped __gc 162 // retrieve wrapped __gc, if any
163 lua_pushvalue(L_, lua_upvalueindex(1)); // L_: self __gc? 163 lua_pushvalue(L_, lua_upvalueindex(1)); // L_: self __gc?
164 if (!lua_isnil(L_, -1)) { 164 if (!lua_isnil(L_, -1)) {
165 lua_insert(L_, -2); // L_: __gc self 165 lua_insert(L_, -2); // L_: __gc self
@@ -175,26 +175,6 @@ void DeepFactory::DeleteDeepObject(lua_State* L_, DeepPrelude* o_)
175 175
176// ################################################################################################# 176// #################################################################################################
177 177
178// TODO: convert to UniqueKey::getSubTableMode
179static void push_registry_subtable_mode(lua_State* L_, RegistryUniqueKey key_, const char* mode_)
180{
181 STACK_GROW(L_, 4);
182 STACK_CHECK_START_REL(L_, 0);
183 if (!key_.getSubTable(L_, 0, 0)) { // L_: {}
184 // Set its metatable if requested
185 if (mode_) {
186 lua_createtable(L_, 0, 1); // L_: {} mt
187 lua_pushliteral(L_, "__mode"); // L_: {} mt "__mode"
188 lua_pushstring(L_, mode_); // L_: {} mt "__mode" mode
189 lua_rawset(L_, -3); // L_: {} mt
190 lua_setmetatable(L_, -2); // L_: {}
191 }
192 }
193 STACK_CHECK(L_, 1);
194}
195
196// #################################################################################################
197
198/* 178/*
199 * Push a proxy userdata on the stack. 179 * Push a proxy userdata on the stack.
200 * returns nullptr if ok, else some error string related to bad factory behavior or module require problem 180 * returns nullptr if ok, else some error string related to bad factory behavior or module require problem
@@ -207,7 +187,7 @@ static void push_registry_subtable_mode(lua_State* L_, RegistryUniqueKey key_, c
207char const* DeepFactory::PushDeepProxy(DestState L_, DeepPrelude* prelude_, int nuv_, LookupMode mode_) 187char const* DeepFactory::PushDeepProxy(DestState L_, DeepPrelude* prelude_, int nuv_, LookupMode mode_)
208{ 188{
209 // Check if a proxy already exists 189 // Check if a proxy already exists
210 push_registry_subtable_mode(L_, kDeepProxyCacheRegKey, "v"); // L_: DPC 190 kDeepProxyCacheRegKey.getSubTableMode(L_, "v"); // L_: DPC
211 lua_pushlightuserdata(L_, prelude_); // L_: DPC deep 191 lua_pushlightuserdata(L_, prelude_); // L_: DPC deep
212 lua_rawget(L_, -2); // L_: DPC proxy 192 lua_rawget(L_, -2); // L_: DPC proxy
213 if (!lua_isnil(L_, -1)) { 193 if (!lua_isnil(L_, -1)) {
@@ -256,7 +236,7 @@ char const* DeepFactory::PushDeepProxy(DestState L_, DeepPrelude* prelude_, int
256 lua_pushcfunction(L_, deep_userdata_gc); // L_: DPC proxy metatable deep_userdata_gc 236 lua_pushcfunction(L_, deep_userdata_gc); // L_: DPC proxy metatable deep_userdata_gc
257 } else { 237 } else {
258 // Add our own '__gc' method wrapping the original 238 // Add our own '__gc' method wrapping the original
259 lua_pushcclosure(L_, deep_userdata_gc, 1); // DPC proxy metatable deep_userdata_gc 239 lua_pushcclosure(L_, deep_userdata_gc, 1); // L_: DPC proxy metatable deep_userdata_gc
260 } 240 }
261 lua_setfield(L_, -2, "__gc"); // L_: DPC proxy metatable 241 lua_setfield(L_, -2, "__gc"); // L_: DPC proxy metatable
262 242