diff options
Diffstat (limited to 'src/deep.cpp')
-rw-r--r-- | src/deep.cpp | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/deep.cpp b/src/deep.cpp index 290e5ff..ac2905e 100644 --- a/src/deep.cpp +++ b/src/deep.cpp | |||
@@ -113,7 +113,7 @@ static void get_deep_lookup( lua_State* L) | |||
113 | static inline luaG_IdFunction get_idfunc( lua_State* L, int index, LookupMode mode_) | 113 | static inline luaG_IdFunction get_idfunc( lua_State* L, int index, LookupMode mode_) |
114 | { | 114 | { |
115 | // when looking inside a keeper, we are 100% sure the object is a deep userdata | 115 | // when looking inside a keeper, we are 100% sure the object is a deep userdata |
116 | if( mode_ == eLM_FromKeeper) | 116 | if (mode_ == LookupMode::FromKeeper) |
117 | { | 117 | { |
118 | DeepPrelude** const proxy{ lua_tofulluserdata<DeepPrelude*>(L, index) }; | 118 | DeepPrelude** const proxy{ lua_tofulluserdata<DeepPrelude*>(L, index) }; |
119 | // we can (and must) cast and fetch the internally stored idfunc | 119 | // we can (and must) cast and fetch the internally stored idfunc |
@@ -149,7 +149,7 @@ void free_deep_prelude( lua_State* L, DeepPrelude* prelude_) | |||
149 | STACK_CHECK_START_REL(L, 0); | 149 | STACK_CHECK_START_REL(L, 0); |
150 | // Call 'idfunc( "delete", deep_ptr )' to make deep cleanup | 150 | // Call 'idfunc( "delete", deep_ptr )' to make deep cleanup |
151 | lua_pushlightuserdata( L, prelude_); | 151 | lua_pushlightuserdata( L, prelude_); |
152 | prelude_->idfunc( L, eDO_delete); | 152 | prelude_->idfunc( L, DeepOp::Delete); |
153 | lua_pop(L, 1); | 153 | lua_pop(L, 1); |
154 | STACK_CHECK(L, 0); | 154 | STACK_CHECK(L, 0); |
155 | } | 155 | } |
@@ -186,7 +186,7 @@ static int deep_userdata_gc( lua_State* L) | |||
186 | // top was set to 0, then userdata was pushed. "delete" might want to pop the userdata (we don't care), but should not push anything! | 186 | // top was set to 0, then userdata was pushed. "delete" might want to pop the userdata (we don't care), but should not push anything! |
187 | if ( lua_gettop( L) > 1) | 187 | if ( lua_gettop( L) > 1) |
188 | { | 188 | { |
189 | return luaL_error( L, "Bad idfunc(eDO_delete): should not push anything"); | 189 | return luaL_error( L, "Bad idfunc(DeepOp::Delete): should not push anything"); |
190 | } | 190 | } |
191 | } | 191 | } |
192 | *proxy = nullptr; // make sure we don't use it any more, just in case | 192 | *proxy = nullptr; // make sure we don't use it any more, just in case |
@@ -197,7 +197,7 @@ static int deep_userdata_gc( lua_State* L) | |||
197 | /* | 197 | /* |
198 | * Push a proxy userdata on the stack. | 198 | * Push a proxy userdata on the stack. |
199 | * returns nullptr if ok, else some error string related to bad idfunc behavior or module require problem | 199 | * returns nullptr if ok, else some error string related to bad idfunc behavior or module require problem |
200 | * (error cannot happen with mode_ == eLM_ToKeeper) | 200 | * (error cannot happen with mode_ == LookupMode::ToKeeper) |
201 | * | 201 | * |
202 | * Initializes necessary structures if it's the first time 'idfunc' is being | 202 | * Initializes necessary structures if it's the first time 'idfunc' is being |
203 | * used in this Lua state (metatable, registring it). Otherwise, increments the | 203 | * used in this Lua state (metatable, registring it). Otherwise, increments the |
@@ -238,9 +238,9 @@ char const* push_deep_proxy(lua_State* L, DeepPrelude* prelude, int nuv_, Lookup | |||
238 | int oldtop = lua_gettop( L); // DPC proxy nil | 238 | int oldtop = lua_gettop( L); // DPC proxy nil |
239 | lua_pop( L, 1); // DPC proxy | 239 | lua_pop( L, 1); // DPC proxy |
240 | // 1 - make one and register it | 240 | // 1 - make one and register it |
241 | if( mode_ != eLM_ToKeeper) | 241 | if (mode_ != LookupMode::ToKeeper) |
242 | { | 242 | { |
243 | (void) prelude->idfunc( L, eDO_metatable); // DPC proxy metatable | 243 | (void) prelude->idfunc( L, DeepOp::Metatable); // DPC proxy metatable |
244 | if( lua_gettop( L) - oldtop != 0 || !lua_istable( L, -1)) | 244 | if( lua_gettop( L) - oldtop != 0 || !lua_istable( L, -1)) |
245 | { | 245 | { |
246 | lua_settop( L, oldtop); // DPC proxy X | 246 | lua_settop( L, oldtop); // DPC proxy X |
@@ -278,7 +278,7 @@ char const* push_deep_proxy(lua_State* L, DeepPrelude* prelude, int nuv_, Lookup | |||
278 | // this is needed because we must make sure the shared library is still loaded as long as we hold a pointer on the idfunc | 278 | // this is needed because we must make sure the shared library is still loaded as long as we hold a pointer on the idfunc |
279 | { | 279 | { |
280 | int oldtop_module = lua_gettop( L); | 280 | int oldtop_module = lua_gettop( L); |
281 | modname = (char const*) prelude->idfunc( L, eDO_module); // DPC proxy metatable | 281 | modname = (char const*) prelude->idfunc( L, DeepOp::Module); // DPC proxy metatable |
282 | // make sure the function pushed nothing on the stack! | 282 | // make sure the function pushed nothing on the stack! |
283 | if( lua_gettop( L) - oldtop_module != 0) | 283 | if( lua_gettop( L) - oldtop_module != 0) |
284 | { | 284 | { |
@@ -358,9 +358,9 @@ char const* push_deep_proxy(lua_State* L, DeepPrelude* prelude, int nuv_, Lookup | |||
358 | * | 358 | * |
359 | * 'idfunc' must fulfill the following features: | 359 | * 'idfunc' must fulfill the following features: |
360 | * | 360 | * |
361 | * lightuserdata = idfunc( eDO_new [, ...] ) -- creates a new deep data instance | 361 | * lightuserdata = idfunc( DeepOp::New [, ...] ) -- creates a new deep data instance |
362 | * void = idfunc( eDO_delete, lightuserdata ) -- releases a deep data instance | 362 | * void = idfunc( DeepOp::Delete, lightuserdata ) -- releases a deep data instance |
363 | * tbl = idfunc( eDO_metatable ) -- gives metatable for userdata proxies | 363 | * tbl = idfunc( DeepOp::Metatable ) -- gives metatable for userdata proxies |
364 | * | 364 | * |
365 | * Reference counting and true userdata proxying are taken care of for the | 365 | * Reference counting and true userdata proxying are taken care of for the |
366 | * actual data type. | 366 | * actual data type. |
@@ -375,18 +375,18 @@ int luaG_newdeepuserdata( lua_State* L, luaG_IdFunction idfunc, int nuv_) | |||
375 | STACK_GROW( L, 1); | 375 | STACK_GROW( L, 1); |
376 | STACK_CHECK_START_REL(L, 0); | 376 | STACK_CHECK_START_REL(L, 0); |
377 | int const oldtop{ lua_gettop(L) }; | 377 | int const oldtop{ lua_gettop(L) }; |
378 | DeepPrelude* const prelude{ static_cast<DeepPrelude*>(idfunc(L, eDO_new)) }; | 378 | DeepPrelude* const prelude{ static_cast<DeepPrelude*>(idfunc(L, DeepOp::New)) }; |
379 | if (prelude == nullptr) | 379 | if (prelude == nullptr) |
380 | { | 380 | { |
381 | return luaL_error( L, "idfunc(eDO_new) failed to create deep userdata (out of memory)"); | 381 | return luaL_error( L, "idfunc(DeepOp::New) failed to create deep userdata (out of memory)"); |
382 | } | 382 | } |
383 | 383 | ||
384 | if( prelude->magic != DEEP_VERSION) | 384 | if( prelude->magic != DEEP_VERSION) |
385 | { | 385 | { |
386 | // just in case, don't leak the newly allocated deep userdata object | 386 | // just in case, don't leak the newly allocated deep userdata object |
387 | lua_pushlightuserdata( L, prelude); | 387 | lua_pushlightuserdata( L, prelude); |
388 | idfunc( L, eDO_delete); | 388 | idfunc( L, DeepOp::Delete); |
389 | return luaL_error( L, "Bad idfunc(eDO_new): DEEP_VERSION is incorrect, rebuild your implementation with the latest deep implementation"); | 389 | return luaL_error( L, "Bad idfunc(DeepOp::New): DEEP_VERSION is incorrect, rebuild your implementation with the latest deep implementation"); |
390 | } | 390 | } |
391 | 391 | ||
392 | ASSERT_L(prelude->m_refcount.load(std::memory_order_relaxed) == 0); // 'push_deep_proxy' will lift it to 1 | 392 | ASSERT_L(prelude->m_refcount.load(std::memory_order_relaxed) == 0); // 'push_deep_proxy' will lift it to 1 |
@@ -396,11 +396,11 @@ int luaG_newdeepuserdata( lua_State* L, luaG_IdFunction idfunc, int nuv_) | |||
396 | { | 396 | { |
397 | // just in case, don't leak the newly allocated deep userdata object | 397 | // just in case, don't leak the newly allocated deep userdata object |
398 | lua_pushlightuserdata( L, prelude); | 398 | lua_pushlightuserdata( L, prelude); |
399 | idfunc( L, eDO_delete); | 399 | idfunc( L, DeepOp::Delete); |
400 | return luaL_error( L, "Bad idfunc(eDO_new): should not push anything on the stack"); | 400 | return luaL_error( L, "Bad idfunc(DeepOp::New): should not push anything on the stack"); |
401 | } | 401 | } |
402 | 402 | ||
403 | char const* const errmsg{ push_deep_proxy(L, prelude, nuv_, eLM_LaneBody) }; // proxy | 403 | char const* const errmsg{ push_deep_proxy(L, prelude, nuv_, LookupMode::LaneBody) }; // proxy |
404 | if (errmsg != nullptr) | 404 | if (errmsg != nullptr) |
405 | { | 405 | { |
406 | return luaL_error( L, errmsg); | 406 | return luaL_error( L, errmsg); |
@@ -420,7 +420,7 @@ DeepPrelude* luaG_todeep(lua_State* L, luaG_IdFunction idfunc, int index) | |||
420 | { | 420 | { |
421 | STACK_CHECK_START_REL(L, 0); | 421 | STACK_CHECK_START_REL(L, 0); |
422 | // ensure it is actually a deep userdata | 422 | // ensure it is actually a deep userdata |
423 | if( get_idfunc( L, index, eLM_LaneBody) != idfunc) | 423 | if (get_idfunc(L, index, LookupMode::LaneBody) != idfunc) |
424 | { | 424 | { |
425 | return nullptr; // no metatable, or wrong kind | 425 | return nullptr; // no metatable, or wrong kind |
426 | } | 426 | } |
@@ -466,7 +466,7 @@ bool copydeep(Universe* U, lua_State* L2, int L2_cache_i, lua_State* L, int i, L | |||
466 | int const clone_i = lua_gettop( L2); | 466 | int const clone_i = lua_gettop( L2); |
467 | while( nuv) | 467 | while( nuv) |
468 | { | 468 | { |
469 | inter_copy_one( U, L2, L2_cache_i, L, lua_absindex( L, -1), VT_NORMAL, mode_, upName_); // u uv | 469 | inter_copy_one( U, L2, L2_cache_i, L, lua_absindex( L, -1), VT::NORMAL, mode_, upName_); // u uv |
470 | lua_pop( L, 1); // ... u [uv]* | 470 | lua_pop( L, 1); // ... u [uv]* |
471 | // this pops the value from the stack | 471 | // this pops the value from the stack |
472 | lua_setiuservalue( L2, clone_i, nuv); // u | 472 | lua_setiuservalue( L2, clone_i, nuv); // u |
@@ -480,7 +480,7 @@ bool copydeep(Universe* U, lua_State* L2, int L2_cache_i, lua_State* L, int i, L | |||
480 | if (errmsg != nullptr) | 480 | if (errmsg != nullptr) |
481 | { | 481 | { |
482 | // raise the error in the proper state (not the keeper) | 482 | // raise the error in the proper state (not the keeper) |
483 | lua_State* const errL { (mode_ == eLM_FromKeeper) ? L2 : L }; | 483 | lua_State* const errL{ (mode_ == LookupMode::FromKeeper) ? L2 : L }; |
484 | std::ignore = luaL_error(errL, errmsg); | 484 | std::ignore = luaL_error(errL, errmsg); |
485 | } | 485 | } |
486 | return true; | 486 | return true; |