diff options
Diffstat (limited to 'src/deep.cpp')
-rw-r--r-- | src/deep.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/deep.cpp b/src/deep.cpp index 82f1214..acd93a6 100644 --- a/src/deep.cpp +++ b/src/deep.cpp | |||
@@ -75,7 +75,7 @@ namespace { | |||
75 | lua_rawget(L_, -2); // L_: {} b | 75 | lua_rawget(L_, -2); // L_: {} b |
76 | } | 76 | } |
77 | lua_remove(L_, -2); // L_: a|b | 77 | lua_remove(L_, -2); // L_: a|b |
78 | LuaType const _type{ luaG_type(L_, kIdxTop) }; | 78 | LuaType const _type{ luaW_type(L_, kIdxTop) }; |
79 | if (_type != LuaType::NIL && _type != expectedType_) { | 79 | if (_type != LuaType::NIL && _type != expectedType_) { |
80 | raise_luaL_error(L_, "INTERNAL ERROR: Unexpected value."); | 80 | raise_luaL_error(L_, "INTERNAL ERROR: Unexpected value."); |
81 | } | 81 | } |
@@ -103,7 +103,7 @@ namespace { | |||
103 | [[nodiscard]] | 103 | [[nodiscard]] |
104 | int DeepFactory::DeepGC(lua_State* const L_) | 104 | int DeepFactory::DeepGC(lua_State* const L_) |
105 | { | 105 | { |
106 | DeepPrelude* const* const _proxy{ luaG_tofulluserdata<DeepPrelude*>(L_, StackIndex{ 1 }) }; | 106 | DeepPrelude* const* const _proxy{ luaW_tofulluserdata<DeepPrelude*>(L_, StackIndex{ 1 }) }; |
107 | DeepPrelude* const _p{ *_proxy }; | 107 | DeepPrelude* const _p{ *_proxy }; |
108 | 108 | ||
109 | // can work without a universe if creating a deep userdata from some external C module when Lanes isn't loaded | 109 | // can work without a universe if creating a deep userdata from some external C module when Lanes isn't loaded |
@@ -150,7 +150,7 @@ DeepFactory* DeepFactory::LookupFactory(lua_State* const L_, StackIndex const in | |||
150 | { | 150 | { |
151 | // when looking inside a keeper, we are 100% sure the object is a deep userdata | 151 | // when looking inside a keeper, we are 100% sure the object is a deep userdata |
152 | if (mode_ == LookupMode::FromKeeper) { | 152 | if (mode_ == LookupMode::FromKeeper) { |
153 | DeepPrelude* const _proxy{ *luaG_tofulluserdata<DeepPrelude*>(L_, index_) }; | 153 | DeepPrelude* const _proxy{ *luaW_tofulluserdata<DeepPrelude*>(L_, index_) }; |
154 | // we can (and must) cast and fetch the internally stored factory | 154 | // we can (and must) cast and fetch the internally stored factory |
155 | return &_proxy->factory; | 155 | return &_proxy->factory; |
156 | } else { | 156 | } else { |
@@ -167,7 +167,7 @@ DeepFactory* DeepFactory::LookupFactory(lua_State* const L_, StackIndex const in | |||
167 | // replace metatable with the factory pointer, if it is actually a deep userdata | 167 | // replace metatable with the factory pointer, if it is actually a deep userdata |
168 | LookupDeep(L_, LuaType::LIGHTUSERDATA); // L_: deep ... factory|nil | 168 | LookupDeep(L_, LuaType::LIGHTUSERDATA); // L_: deep ... factory|nil |
169 | 169 | ||
170 | DeepFactory* const _ret{ luaG_tolightuserdata<DeepFactory>(L_, kIdxTop) }; // nullptr if not a userdata | 170 | DeepFactory* const _ret{ luaW_tolightuserdata<DeepFactory>(L_, kIdxTop) }; // nullptr if not a userdata |
171 | lua_pop(L_, 1); | 171 | lua_pop(L_, 1); |
172 | STACK_CHECK(L_, 0); | 172 | STACK_CHECK(L_, 0); |
173 | return _ret; | 173 | return _ret; |
@@ -190,7 +190,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
190 | 190 | ||
191 | // Check if a proxy already exists | 191 | // Check if a proxy already exists |
192 | lua_pushlightuserdata(L_, prelude_); // L_: DPC deep | 192 | lua_pushlightuserdata(L_, prelude_); // L_: DPC deep |
193 | if (luaG_rawget(L_, StackIndex{ -2 }) != LuaType::NIL) { // L_: DPC proxy | 193 | if (luaW_rawget(L_, StackIndex{ -2 }) != LuaType::NIL) { // L_: DPC proxy |
194 | lua_remove(L_, -2); // L_: proxy | 194 | lua_remove(L_, -2); // L_: proxy |
195 | STACK_CHECK(L_, 1); | 195 | STACK_CHECK(L_, 1); |
196 | return; | 196 | return; |
@@ -202,7 +202,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
202 | STACK_GROW(L_, 7); | 202 | STACK_GROW(L_, 7); |
203 | 203 | ||
204 | // a new full userdata, fitted with the specified number of uservalue slots (always 1 for Lua < 5.4) | 204 | // a new full userdata, fitted with the specified number of uservalue slots (always 1 for Lua < 5.4) |
205 | DeepPrelude** const _proxy{ luaG_newuserdatauv<DeepPrelude*>(L_, nuv_) }; // L_: DPC proxy | 205 | DeepPrelude** const _proxy{ luaW_newuserdatauv<DeepPrelude*>(L_, nuv_) }; // L_: DPC proxy |
206 | LUA_ASSERT(L_, _proxy); | 206 | LUA_ASSERT(L_, _proxy); |
207 | *_proxy = prelude_; | 207 | *_proxy = prelude_; |
208 | prelude_->refcount.fetch_add(1, std::memory_order_relaxed); // one more proxy pointing to this deep data | 208 | prelude_->refcount.fetch_add(1, std::memory_order_relaxed); // one more proxy pointing to this deep data |
@@ -223,7 +223,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
223 | raise_luaL_error(errL_, "Bad DeepFactory::createMetatable overload: unexpected pushed value"); | 223 | raise_luaL_error(errL_, "Bad DeepFactory::createMetatable overload: unexpected pushed value"); |
224 | } | 224 | } |
225 | // if the metatable contains a __gc, we will call it from our own | 225 | // if the metatable contains a __gc, we will call it from our own |
226 | std::ignore = luaG_rawgetfield(L_, kIdxTop, "__gc"); // L_: DPC proxy metatable __gc | 226 | std::ignore = luaW_rawgetfield(L_, kIdxTop, "__gc"); // L_: DPC proxy metatable __gc |
227 | } else { | 227 | } else { |
228 | // keepers need a minimal metatable that only contains our own __gc | 228 | // keepers need a minimal metatable that only contains our own __gc |
229 | lua_createtable(L_, 0, 1); // L_: DPC proxy metatable | 229 | lua_createtable(L_, 0, 1); // L_: DPC proxy metatable |
@@ -251,8 +251,8 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
251 | raise_luaL_error(errL_, "lanes receiving deep userdata should register the 'package' library"); | 251 | raise_luaL_error(errL_, "lanes receiving deep userdata should register the 'package' library"); |
252 | } | 252 | } |
253 | 253 | ||
254 | luaG_pushstring(L_, _modname); // L_: DPC proxy metatable require() "module" | 254 | luaW_pushstring(L_, _modname); // L_: DPC proxy metatable require() "module" |
255 | if (luaG_getfield(L_, kIdxRegistry, LUA_LOADED_TABLE) != LuaType::TABLE) { // L_: DPC proxy metatable require() "module" _R._LOADED | 255 | if (luaW_getfield(L_, kIdxRegistry, LUA_LOADED_TABLE) != LuaType::TABLE) { // L_: DPC proxy metatable require() "module" _R._LOADED |
256 | // no L.registry._LOADED; can this ever happen? | 256 | // no L.registry._LOADED; can this ever happen? |
257 | lua_pop(L_, 6); // L_: | 257 | lua_pop(L_, 6); // L_: |
258 | raise_luaL_error(errL_, "unexpected error while requiring a module identified by DeepFactory::moduleName"); | 258 | raise_luaL_error(errL_, "unexpected error while requiring a module identified by DeepFactory::moduleName"); |
@@ -270,7 +270,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
270 | LuaError const _require_result{ lua_pcall(L_, 1, 0, 0) }; // L_: DPC proxy metatable error? | 270 | LuaError const _require_result{ lua_pcall(L_, 1, 0, 0) }; // L_: DPC proxy metatable error? |
271 | if (_require_result != LuaError::OK) { | 271 | if (_require_result != LuaError::OK) { |
272 | // failed, raise the error in the proper state | 272 | // failed, raise the error in the proper state |
273 | raise_luaL_error(errL_, luaG_tostring(L_, kIdxTop)); | 273 | raise_luaL_error(errL_, luaW_tostring(L_, kIdxTop)); |
274 | } | 274 | } |
275 | } | 275 | } |
276 | } else { // already loaded, we are happy | 276 | } else { // already loaded, we are happy |
@@ -279,7 +279,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
279 | } | 279 | } |
280 | } | 280 | } |
281 | STACK_CHECK(L_, 3); // L_: DPC proxy metatable | 281 | STACK_CHECK(L_, 3); // L_: DPC proxy metatable |
282 | LUA_ASSERT(L_, luaG_type(L_, StackIndex{ -2 }) == LuaType::USERDATA); | 282 | LUA_ASSERT(L_, luaW_type(L_, StackIndex{ -2 }) == LuaType::USERDATA); |
283 | LUA_ASSERT(L_, lua_istable(L_, -1)); | 283 | LUA_ASSERT(L_, lua_istable(L_, -1)); |
284 | lua_setmetatable(L_, -2); // L_: DPC proxy | 284 | lua_setmetatable(L_, -2); // L_: DPC proxy |
285 | 285 | ||
@@ -288,7 +288,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
288 | lua_pushvalue(L_, -2); // L_: DPC proxy deep proxy | 288 | lua_pushvalue(L_, -2); // L_: DPC proxy deep proxy |
289 | lua_rawset(L_, -4); // L_: DPC proxy | 289 | lua_rawset(L_, -4); // L_: DPC proxy |
290 | lua_remove(L_, -2); // L_: proxy | 290 | lua_remove(L_, -2); // L_: proxy |
291 | LUA_ASSERT(L_, luaG_type(L_, kIdxTop) == LuaType::USERDATA); | 291 | LUA_ASSERT(L_, luaW_type(L_, kIdxTop) == LuaType::USERDATA); |
292 | STACK_CHECK(L_, 1); | 292 | STACK_CHECK(L_, 1); |
293 | } | 293 | } |
294 | 294 | ||
@@ -305,7 +305,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
305 | * Reference counting and true userdata proxying are taken care of for the actual data type. | 305 | * Reference counting and true userdata proxying are taken care of for the actual data type. |
306 | * | 306 | * |
307 | * Types using the deep userdata system (and only those!) can be passed between | 307 | * Types using the deep userdata system (and only those!) can be passed between |
308 | * separate Lua states via 'luaG_inter_move()'. | 308 | * separate Lua states via 'luaW_inter_move()'. |
309 | * | 309 | * |
310 | * Returns: 'proxy' userdata for accessing the deep data via 'DeepFactory::toDeep()' | 310 | * Returns: 'proxy' userdata for accessing the deep data via 'DeepFactory::toDeep()' |
311 | */ | 311 | */ |
@@ -382,7 +382,7 @@ DeepPrelude* DeepFactory::toDeep(lua_State* const L_, StackIndex const index_) c | |||
382 | } | 382 | } |
383 | STACK_CHECK(L_, 0); | 383 | STACK_CHECK(L_, 0); |
384 | 384 | ||
385 | DeepPrelude** const _proxy{ luaG_tofulluserdata<DeepPrelude*>(L_, index_) }; | 385 | DeepPrelude** const _proxy{ luaW_tofulluserdata<DeepPrelude*>(L_, index_) }; |
386 | return *_proxy; | 386 | return *_proxy; |
387 | } | 387 | } |
388 | 388 | ||