diff options
Diffstat (limited to 'src/deep.cpp')
-rw-r--r-- | src/deep.cpp | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/src/deep.cpp b/src/deep.cpp index 3b0e015..3eb38dc 100644 --- a/src/deep.cpp +++ b/src/deep.cpp | |||
@@ -411,39 +411,41 @@ DeepPrelude* DeepFactory::toDeep(lua_State* L, int index) const | |||
411 | * the id function of the copied value, or nullptr for non-deep userdata | 411 | * the id function of the copied value, or nullptr for non-deep userdata |
412 | * (not copied) | 412 | * (not copied) |
413 | */ | 413 | */ |
414 | bool copydeep(Universe* U, Dest L2, int L2_cache_i, Source L, int i, LookupMode mode_, char const* upName_) | 414 | [[nodiscard]] bool InterCopyContext::copydeep() const |
415 | { | 415 | { |
416 | DeepFactory* const factory { get_factory(L, i, mode_) }; | 416 | DeepFactory* const factory { get_factory(L1, L1_i, mode) }; |
417 | if (factory == nullptr) | 417 | if (factory == nullptr) |
418 | { | 418 | { |
419 | return false; // not a deep userdata | 419 | return false; // not a deep userdata |
420 | } | 420 | } |
421 | 421 | ||
422 | STACK_CHECK_START_REL(L, 0); | 422 | STACK_CHECK_START_REL(L1, 0); |
423 | STACK_CHECK_START_REL(L2, 0); | 423 | STACK_CHECK_START_REL(L2, 0); |
424 | 424 | ||
425 | // extract all uservalues of the source | 425 | // extract all uservalues of the source |
426 | int nuv = 0; | 426 | int nuv = 0; |
427 | while (lua_getiuservalue(L, i, nuv + 1) != LUA_TNONE) // ... u [uv]* nil | 427 | while (lua_getiuservalue(L1, L1_i, nuv + 1) != LUA_TNONE) // ... u [uv]* nil |
428 | { | 428 | { |
429 | ++ nuv; | 429 | ++ nuv; |
430 | } | 430 | } |
431 | // last call returned TNONE and pushed nil, that we don't need | 431 | // last call returned TNONE and pushed nil, that we don't need |
432 | lua_pop( L, 1); // ... u [uv]* | 432 | lua_pop(L1, 1); // ... u [uv]* |
433 | STACK_CHECK( L, nuv); | 433 | STACK_CHECK(L1, nuv); |
434 | 434 | ||
435 | char const* errmsg{ DeepFactory::PushDeepProxy(L2, *lua_tofulluserdata<DeepPrelude*>(L, i), nuv, mode_) }; // u | 435 | char const* errmsg{ DeepFactory::PushDeepProxy(L2, *lua_tofulluserdata<DeepPrelude*>(L1, L1_i), nuv, mode) }; // u |
436 | 436 | ||
437 | // transfer all uservalues of the source in the destination | 437 | // transfer all uservalues of the source in the destination |
438 | { | 438 | { |
439 | int const clone_i = lua_gettop( L2); | 439 | InterCopyContext c{ U, L2, L1, L2_cache_i, {}, VT::NORMAL, mode, name }; |
440 | while( nuv) | 440 | int const clone_i{ lua_gettop(L2) }; |
441 | while (nuv) | ||
441 | { | 442 | { |
442 | if (!inter_copy_one(U, L2, L2_cache_i, L, lua_absindex(L, -1), VT::NORMAL, mode_, upName_)) // u uv | 443 | c.L1_i = SourceIndex{ lua_absindex(L1, -1) }; |
444 | if (!c.inter_copy_one()) // u uv | ||
443 | { | 445 | { |
444 | return luaL_error(L, "Cannot copy upvalue type '%s'", luaL_typename(L, -1)); | 446 | luaL_error(L1, "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); // doesn't return |
445 | } | 447 | } |
446 | lua_pop( L, 1); // ... u [uv]* | 448 | lua_pop(L1, 1); // ... u [uv]* |
447 | // this pops the value from the stack | 449 | // this pops the value from the stack |
448 | lua_setiuservalue(L2, clone_i, nuv); // u | 450 | lua_setiuservalue(L2, clone_i, nuv); // u |
449 | -- nuv; | 451 | -- nuv; |
@@ -451,12 +453,12 @@ bool copydeep(Universe* U, Dest L2, int L2_cache_i, Source L, int i, LookupMode | |||
451 | } | 453 | } |
452 | 454 | ||
453 | STACK_CHECK(L2, 1); | 455 | STACK_CHECK(L2, 1); |
454 | STACK_CHECK(L, 0); | 456 | STACK_CHECK(L1, 0); |
455 | 457 | ||
456 | if (errmsg != nullptr) | 458 | if (errmsg != nullptr) |
457 | { | 459 | { |
458 | // raise the error in the proper state (not the keeper) | 460 | // raise the error in the proper state (not the keeper) |
459 | lua_State* const errL{ (mode_ == LookupMode::FromKeeper) ? L2 : L }; | 461 | lua_State* const errL{ (mode == LookupMode::FromKeeper) ? L2 : L1 }; |
460 | luaL_error(errL, errmsg); // doesn't return | 462 | luaL_error(errL, errmsg); // doesn't return |
461 | } | 463 | } |
462 | return true; | 464 | return true; |