diff options
Diffstat (limited to 'src/deep.cpp')
-rw-r--r-- | src/deep.cpp | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/deep.cpp b/src/deep.cpp index a824f72..735a14c 100644 --- a/src/deep.cpp +++ b/src/deep.cpp | |||
@@ -381,7 +381,7 @@ DeepPrelude* DeepFactory::toDeep(lua_State* L_, int index_) const | |||
381 | STACK_CHECK_START_REL(L1, 0); | 381 | STACK_CHECK_START_REL(L1, 0); |
382 | STACK_CHECK_START_REL(L2, 0); | 382 | STACK_CHECK_START_REL(L2, 0); |
383 | 383 | ||
384 | // extract all uservalues of the source | 384 | // extract all uservalues of the source. unfortunately, the only way to know their count is to iterate until we fail |
385 | int nuv = 0; | 385 | int nuv = 0; |
386 | while (lua_getiuservalue(L1, L1_i, nuv + 1) != LUA_TNONE) { // L1: ... u [uv]* nil | 386 | while (lua_getiuservalue(L1, L1_i, nuv + 1) != LUA_TNONE) { // L1: ... u [uv]* nil |
387 | ++nuv; | 387 | ++nuv; |
@@ -391,7 +391,10 @@ DeepPrelude* DeepFactory::toDeep(lua_State* L_, int index_) const | |||
391 | STACK_CHECK(L1, nuv); | 391 | STACK_CHECK(L1, nuv); |
392 | 392 | ||
393 | DeepPrelude* const u{ *lua_tofulluserdata<DeepPrelude*>(L1, L1_i) }; | 393 | DeepPrelude* const u{ *lua_tofulluserdata<DeepPrelude*>(L1, L1_i) }; |
394 | char const* errmsg{ DeepFactory::PushDeepProxy(L2, u, nuv, mode) }; // L2: u | 394 | char const* errmsg{ DeepFactory::PushDeepProxy(L2, u, nuv, mode) }; // L1: ... u [uv]* L2: u |
395 | if (errmsg != nullptr) { | ||
396 | raise_luaL_error(getErrL(), errmsg); | ||
397 | } | ||
395 | 398 | ||
396 | // transfer all uservalues of the source in the destination | 399 | // transfer all uservalues of the source in the destination |
397 | { | 400 | { |
@@ -399,8 +402,8 @@ DeepPrelude* DeepFactory::toDeep(lua_State* L_, int index_) const | |||
399 | int const clone_i{ lua_gettop(L2) }; | 402 | int const clone_i{ lua_gettop(L2) }; |
400 | while (nuv) { | 403 | while (nuv) { |
401 | c.L1_i = SourceIndex{ lua_absindex(L1, -1) }; | 404 | c.L1_i = SourceIndex{ lua_absindex(L1, -1) }; |
402 | if (!c.inter_copy_one()) { // L2: u uv | 405 | if (!c.inter_copy_one()) { // L1: ... u [uv]* L2: u uv |
403 | raise_luaL_error(L1, "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); | 406 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); |
404 | } | 407 | } |
405 | lua_pop(L1, 1); // L1: ... u [uv]* | 408 | lua_pop(L1, 1); // L1: ... u [uv]* |
406 | // this pops the value from the stack | 409 | // this pops the value from the stack |
@@ -412,10 +415,5 @@ DeepPrelude* DeepFactory::toDeep(lua_State* L_, int index_) const | |||
412 | STACK_CHECK(L2, 1); | 415 | STACK_CHECK(L2, 1); |
413 | STACK_CHECK(L1, 0); | 416 | STACK_CHECK(L1, 0); |
414 | 417 | ||
415 | if (errmsg != nullptr) { | ||
416 | // raise the error in the proper state (not the keeper) | ||
417 | lua_State* const errL{ (mode == LookupMode::FromKeeper) ? L2 : L1 }; | ||
418 | raise_luaL_error(errL, errmsg); | ||
419 | } | ||
420 | return true; | 418 | return true; |
421 | } \ No newline at end of file | 419 | } \ No newline at end of file |