diff options
-rw-r--r-- | src/intercopycontext.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index 1b84641..e29132d 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp | |||
@@ -1240,7 +1240,9 @@ namespace { | |||
1240 | } else { | 1240 | } else { |
1241 | { | 1241 | { |
1242 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); | 1242 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); |
1243 | _result = interMove(1); // moves the entry to L2 | 1243 | // to move, we need a context with L1_i set to 0 |
1244 | InterCopyContext _c{ U, L2, L1, L2_cache_i, {}, vt, mode, name }; | ||
1245 | _result = _c.interMove(1); // moves the entry to L2 | ||
1244 | STACK_CHECK(L1, 0); | 1246 | STACK_CHECK(L1, 0); |
1245 | } | 1247 | } |
1246 | if (_result == InterCopyResult::Success) { | 1248 | if (_result == InterCopyResult::Success) { |
@@ -1272,7 +1274,8 @@ namespace { | |||
1272 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); | 1274 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); |
1273 | 1275 | ||
1274 | int const _top_L1{ lua_gettop(L1) }; | 1276 | int const _top_L1{ lua_gettop(L1) }; |
1275 | if (n_ > _top_L1) { | 1277 | int const _available{ (L1_i != 0) ? (_top_L1 - L1_i + 1) : _top_L1 }; |
1278 | if (n_ > _available) { | ||
1276 | // requesting to copy more than is available? | 1279 | // requesting to copy more than is available? |
1277 | DEBUGSPEW_CODE(DebugSpew(U) << "nothing to copy" << std::endl); | 1280 | DEBUGSPEW_CODE(DebugSpew(U) << "nothing to copy" << std::endl); |
1278 | return InterCopyResult::NotEnoughValues; | 1281 | return InterCopyResult::NotEnoughValues; |
@@ -1292,7 +1295,8 @@ namespace { | |||
1292 | InterCopyContext _c{ U, L2, L1, CacheIndex{ _top_L2 + 1 }, {}, VT::NORMAL, mode, "?" }; | 1295 | InterCopyContext _c{ U, L2, L1, CacheIndex{ _top_L2 + 1 }, {}, VT::NORMAL, mode, "?" }; |
1293 | InterCopyResult _copyok{ InterCopyResult::Success }; | 1296 | InterCopyResult _copyok{ InterCopyResult::Success }; |
1294 | STACK_CHECK_START_REL(L1, 0); | 1297 | STACK_CHECK_START_REL(L1, 0); |
1295 | for (int _i{ _top_L1 - n_ + 1 }, _j{ 1 }; _i <= _top_L1; ++_i, ++_j) { | 1298 | // if L1_i is specified, start here, else take the _n items off the top of the stack |
1299 | for (int _i{ L1_i != 0 ? L1_i : (_top_L1 - n_ + 1) }, _j{ 1 }; _j <= n_; ++_i, ++_j) { | ||
1296 | char _tmpBuf[16]; | 1300 | char _tmpBuf[16]; |
1297 | if (U->verboseErrors) { | 1301 | if (U->verboseErrors) { |
1298 | sprintf(_tmpBuf, "arg_%d", _j); | 1302 | sprintf(_tmpBuf, "arg_%d", _j); |
@@ -1324,6 +1328,7 @@ namespace { | |||
1324 | 1328 | ||
1325 | [[nodiscard]] InterCopyResult InterCopyContext::interMove(int const n_) const | 1329 | [[nodiscard]] InterCopyResult InterCopyContext::interMove(int const n_) const |
1326 | { | 1330 | { |
1331 | assert(L1_i == 0); // we can only move stuff off the top of the stack | ||
1327 | InterCopyResult const _ret{ interCopy(n_) }; | 1332 | InterCopyResult const _ret{ interCopy(n_) }; |
1328 | lua_pop(L1, n_); | 1333 | lua_pop(L1, n_); |
1329 | return _ret; | 1334 | return _ret; |