diff options
Diffstat (limited to '')
-rw-r--r-- | src/deep.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/deep.cpp b/src/deep.cpp index bac011f..a244f8b 100644 --- a/src/deep.cpp +++ b/src/deep.cpp | |||
@@ -70,7 +70,7 @@ namespace { | |||
70 | */ | 70 | */ |
71 | [[nodiscard]] static int DeepGC(lua_State* const L_) | 71 | [[nodiscard]] static int DeepGC(lua_State* const L_) |
72 | { | 72 | { |
73 | DeepPrelude* const* const _proxy{ luaG_tofulluserdata<DeepPrelude*>(L_, 1) }; | 73 | DeepPrelude* const* const _proxy{ luaG_tofulluserdata<DeepPrelude*>(L_, StackIndex{ 1 }) }; |
74 | DeepPrelude* const _p{ *_proxy }; | 74 | DeepPrelude* const _p{ *_proxy }; |
75 | 75 | ||
76 | // can work without a universe if creating a deep userdata from some external C module when Lanes isn't loaded | 76 | // can work without a universe if creating a deep userdata from some external C module when Lanes isn't loaded |
@@ -130,7 +130,7 @@ void DeepFactory::DeleteDeepObject(lua_State* const L_, DeepPrelude* const o_) | |||
130 | 130 | ||
131 | // ################################################################################################# | 131 | // ################################################################################################# |
132 | 132 | ||
133 | bool DeepFactory::IsDeepUserdata(lua_State* const L_, int const idx_) | 133 | bool DeepFactory::IsDeepUserdata(lua_State* const L_, StackIndex const idx_) |
134 | { | 134 | { |
135 | return LookupFactory(L_, idx_, LookupMode::LaneBody) != nullptr; | 135 | return LookupFactory(L_, idx_, LookupMode::LaneBody) != nullptr; |
136 | } | 136 | } |
@@ -138,7 +138,7 @@ bool DeepFactory::IsDeepUserdata(lua_State* const L_, int const idx_) | |||
138 | // ################################################################################################# | 138 | // ################################################################################################# |
139 | 139 | ||
140 | // Return the registered factory for 'index' (deep userdata proxy), or nullptr if 'index' is not a deep userdata proxy. | 140 | // Return the registered factory for 'index' (deep userdata proxy), or nullptr if 'index' is not a deep userdata proxy. |
141 | DeepFactory* DeepFactory::LookupFactory(lua_State* const L_, int const index_, LookupMode const mode_) | 141 | DeepFactory* DeepFactory::LookupFactory(lua_State* const L_, StackIndex const index_, LookupMode const mode_) |
142 | { | 142 | { |
143 | // when looking inside a keeper, we are 100% sure the object is a deep userdata | 143 | // when looking inside a keeper, we are 100% sure the object is a deep userdata |
144 | if (mode_ == LookupMode::FromKeeper) { | 144 | if (mode_ == LookupMode::FromKeeper) { |
@@ -159,7 +159,7 @@ DeepFactory* DeepFactory::LookupFactory(lua_State* const L_, int const index_, L | |||
159 | // replace metatable with the factory pointer, if it is actually a deep userdata | 159 | // replace metatable with the factory pointer, if it is actually a deep userdata |
160 | LookupDeep(L_); // L_: deep ... factory|nil | 160 | LookupDeep(L_); // L_: deep ... factory|nil |
161 | 161 | ||
162 | DeepFactory* const _ret{ luaG_tolightuserdata<DeepFactory>(L_, -1) }; // nullptr if not a userdata | 162 | DeepFactory* const _ret{ luaG_tolightuserdata<DeepFactory>(L_, kIdxTop) }; // nullptr if not a userdata |
163 | lua_pop(L_, 1); | 163 | lua_pop(L_, 1); |
164 | STACK_CHECK(L_, 0); | 164 | STACK_CHECK(L_, 0); |
165 | return _ret; | 165 | return _ret; |
@@ -207,7 +207,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
207 | 207 | ||
208 | if (lua_isnil(L_, -1)) { // No metatable yet. | 208 | if (lua_isnil(L_, -1)) { // No metatable yet. |
209 | lua_pop(L_, 1); // L_: DPC proxy | 209 | lua_pop(L_, 1); // L_: DPC proxy |
210 | int const _oldtop{ lua_gettop(L_) }; | 210 | StackIndex const _oldtop{ lua_gettop(L_) }; |
211 | // 1 - make one and register it | 211 | // 1 - make one and register it |
212 | if (mode_ != LookupMode::ToKeeper) { | 212 | if (mode_ != LookupMode::ToKeeper) { |
213 | _factory.createMetatable(L_); // L_: DPC proxy metatable | 213 | _factory.createMetatable(L_); // L_: DPC proxy metatable |
@@ -216,7 +216,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
216 | raise_luaL_error(errL_, "Bad DeepFactory::createMetatable overload: unexpected pushed value"); | 216 | raise_luaL_error(errL_, "Bad DeepFactory::createMetatable overload: unexpected pushed value"); |
217 | } | 217 | } |
218 | // if the metatable contains a __gc, we will call it from our own | 218 | // if the metatable contains a __gc, we will call it from our own |
219 | std::ignore = luaG_getfield(L_, -1, "__gc"); // L_: DPC proxy metatable __gc | 219 | std::ignore = luaG_getfield(L_, kIdxTop, "__gc"); // L_: DPC proxy metatable __gc |
220 | } else { | 220 | } else { |
221 | // keepers need a minimal metatable that only contains our own __gc | 221 | // keepers need a minimal metatable that only contains our own __gc |
222 | lua_createtable(L_, 0, 1); // L_: DPC proxy metatable | 222 | lua_createtable(L_, 0, 1); // L_: DPC proxy metatable |
@@ -245,7 +245,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
245 | } | 245 | } |
246 | 246 | ||
247 | luaG_pushstring(L_, _modname); // L_: DPC proxy metatable require() "module" | 247 | luaG_pushstring(L_, _modname); // L_: DPC proxy metatable require() "module" |
248 | if (luaG_getfield(L_, LUA_REGISTRYINDEX, LUA_LOADED_TABLE) != LuaType::TABLE) { // L_: DPC proxy metatable require() "module" _R._LOADED | 248 | if (luaG_getfield(L_, kIdxRegistry, LUA_LOADED_TABLE) != LuaType::TABLE) { // L_: DPC proxy metatable require() "module" _R._LOADED |
249 | // no L.registry._LOADED; can this ever happen? | 249 | // no L.registry._LOADED; can this ever happen? |
250 | lua_pop(L_, 6); // L_: | 250 | lua_pop(L_, 6); // L_: |
251 | raise_luaL_error(errL_, "unexpected error while requiring a module identified by DeepFactory::moduleName"); | 251 | raise_luaL_error(errL_, "unexpected error while requiring a module identified by DeepFactory::moduleName"); |
@@ -263,7 +263,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
263 | LuaError const _require_result{ lua_pcall(L_, 1, 0, 0) }; // L_: DPC proxy metatable error? | 263 | LuaError const _require_result{ lua_pcall(L_, 1, 0, 0) }; // L_: DPC proxy metatable error? |
264 | if (_require_result != LuaError::OK) { | 264 | if (_require_result != LuaError::OK) { |
265 | // failed, raise the error in the proper state | 265 | // failed, raise the error in the proper state |
266 | raise_luaL_error(errL_, luaG_tostring(L_, -1)); | 266 | raise_luaL_error(errL_, luaG_tostring(L_, kIdxTop)); |
267 | } | 267 | } |
268 | } | 268 | } |
269 | } else { // already loaded, we are happy | 269 | } else { // already loaded, we are happy |
@@ -272,7 +272,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
272 | } | 272 | } |
273 | } | 273 | } |
274 | STACK_CHECK(L_, 3); // L_: DPC proxy metatable | 274 | STACK_CHECK(L_, 3); // L_: DPC proxy metatable |
275 | LUA_ASSERT(L_, luaG_type(L_, -2) == LuaType::USERDATA); | 275 | LUA_ASSERT(L_, luaG_type(L_, StackIndex{ -2 }) == LuaType::USERDATA); |
276 | LUA_ASSERT(L_, lua_istable(L_, -1)); | 276 | LUA_ASSERT(L_, lua_istable(L_, -1)); |
277 | lua_setmetatable(L_, -2); // L_: DPC proxy | 277 | lua_setmetatable(L_, -2); // L_: DPC proxy |
278 | 278 | ||
@@ -281,7 +281,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
281 | lua_pushvalue(L_, -2); // L_: DPC proxy deep proxy | 281 | lua_pushvalue(L_, -2); // L_: DPC proxy deep proxy |
282 | lua_rawset(L_, -4); // L_: DPC proxy | 282 | lua_rawset(L_, -4); // L_: DPC proxy |
283 | lua_remove(L_, -2); // L_: proxy | 283 | lua_remove(L_, -2); // L_: proxy |
284 | LUA_ASSERT(L_, luaG_type(L_, -1) == LuaType::USERDATA); | 284 | LUA_ASSERT(L_, luaG_type(L_, kIdxTop) == LuaType::USERDATA); |
285 | STACK_CHECK(L_, 1); | 285 | STACK_CHECK(L_, 1); |
286 | } | 286 | } |
287 | 287 | ||
@@ -306,7 +306,7 @@ void DeepFactory::pushDeepUserdata(DestState const L_, int const nuv_) const | |||
306 | { | 306 | { |
307 | STACK_GROW(L_, 1); | 307 | STACK_GROW(L_, 1); |
308 | STACK_CHECK_START_REL(L_, 0); | 308 | STACK_CHECK_START_REL(L_, 0); |
309 | int const _oldtop{ lua_gettop(L_) }; | 309 | StackIndex const _oldtop{ lua_gettop(L_) }; |
310 | DeepPrelude* const _prelude{ newDeepObjectInternal(L_) }; | 310 | DeepPrelude* const _prelude{ newDeepObjectInternal(L_) }; |
311 | if (_prelude == nullptr) { | 311 | if (_prelude == nullptr) { |
312 | raise_luaL_error(L_, "DeepFactory::newDeepObjectInternal failed to create deep userdata (out of memory)"); | 312 | raise_luaL_error(L_, "DeepFactory::newDeepObjectInternal failed to create deep userdata (out of memory)"); |
@@ -365,7 +365,7 @@ void DeepFactory::storeDeepLookup(lua_State* const L_) const | |||
365 | * Reference count is not changed, and access to the deep userdata is not | 365 | * Reference count is not changed, and access to the deep userdata is not |
366 | * serialized. It is the module's responsibility to prevent conflicting usage. | 366 | * serialized. It is the module's responsibility to prevent conflicting usage. |
367 | */ | 367 | */ |
368 | DeepPrelude* DeepFactory::toDeep(lua_State* const L_, int const index_) const | 368 | DeepPrelude* DeepFactory::toDeep(lua_State* const L_, StackIndex const index_) const |
369 | { | 369 | { |
370 | STACK_CHECK_START_REL(L_, 0); | 370 | STACK_CHECK_START_REL(L_, 0); |
371 | // ensure it is actually a deep userdata we created | 371 | // ensure it is actually a deep userdata we created |