diff options
Diffstat (limited to 'src/tools.cpp')
-rw-r--r-- | src/tools.cpp | 252 |
1 files changed, 126 insertions, 126 deletions
diff --git a/src/tools.cpp b/src/tools.cpp index 5196e7e..1e38144 100644 --- a/src/tools.cpp +++ b/src/tools.cpp | |||
@@ -62,10 +62,10 @@ DEBUGSPEW_CODE( char const* debugspew_indent = "----+----!----+----!----+----!-- | |||
62 | void push_registry_subtable_mode( lua_State* L, UniqueKey key_, const char* mode_) | 62 | void push_registry_subtable_mode( lua_State* L, UniqueKey key_, const char* mode_) |
63 | { | 63 | { |
64 | STACK_GROW(L, 3); | 64 | STACK_GROW(L, 3); |
65 | STACK_CHECK(L, 0); | 65 | STACK_CHECK_START_REL(L, 0); |
66 | 66 | ||
67 | key_.query_registry(L); // {}|nil | 67 | key_.query_registry(L); // {}|nil |
68 | STACK_MID(L, 1); | 68 | STACK_CHECK(L, 1); |
69 | 69 | ||
70 | if (lua_isnil(L, -1)) | 70 | if (lua_isnil(L, -1)) |
71 | { | 71 | { |
@@ -73,7 +73,7 @@ void push_registry_subtable_mode( lua_State* L, UniqueKey key_, const char* mode | |||
73 | lua_newtable(L); // {} | 73 | lua_newtable(L); // {} |
74 | // _R[key_] = {} | 74 | // _R[key_] = {} |
75 | key_.set_registry(L, [](lua_State* L) { lua_pushvalue(L, -2); }); // {} | 75 | key_.set_registry(L, [](lua_State* L) { lua_pushvalue(L, -2); }); // {} |
76 | STACK_MID(L, 1); | 76 | STACK_CHECK(L, 1); |
77 | 77 | ||
78 | // Set its metatable if requested | 78 | // Set its metatable if requested |
79 | if (mode_) | 79 | if (mode_) |
@@ -85,7 +85,7 @@ void push_registry_subtable_mode( lua_State* L, UniqueKey key_, const char* mode | |||
85 | lua_setmetatable(L, -2); // {} | 85 | lua_setmetatable(L, -2); // {} |
86 | } | 86 | } |
87 | } | 87 | } |
88 | STACK_END(L, 1); | 88 | STACK_CHECK(L, 1); |
89 | ASSERT_L(lua_istable(L, -1)); | 89 | ASSERT_L(lua_istable(L, -1)); |
90 | } | 90 | } |
91 | 91 | ||
@@ -125,7 +125,7 @@ void luaG_dump( lua_State* L) | |||
125 | // Note: this requires 'tostring()' to be defined. If it is NOT, | 125 | // Note: this requires 'tostring()' to be defined. If it is NOT, |
126 | // enable it for more debugging. | 126 | // enable it for more debugging. |
127 | // | 127 | // |
128 | STACK_CHECK( L, 0); | 128 | STACK_CHECK_START_REL(L, 0); |
129 | STACK_GROW( L, 2); | 129 | STACK_GROW( L, 2); |
130 | 130 | ||
131 | lua_getglobal( L, "tostring"); | 131 | lua_getglobal( L, "tostring"); |
@@ -146,7 +146,7 @@ void luaG_dump( lua_State* L) | |||
146 | fprintf( stderr, "%s", lua_tostring( L, -1)); | 146 | fprintf( stderr, "%s", lua_tostring( L, -1)); |
147 | } | 147 | } |
148 | lua_pop( L, 1); | 148 | lua_pop( L, 1); |
149 | STACK_END( L, 0); | 149 | STACK_CHECK( L, 0); |
150 | fprintf( stderr, "\n"); | 150 | fprintf( stderr, "\n"); |
151 | } | 151 | } |
152 | fprintf( stderr, "\n"); | 152 | fprintf( stderr, "\n"); |
@@ -193,7 +193,7 @@ static int luaG_provide_protected_allocator( lua_State* L) | |||
193 | // Do I need to disable this when compiling for LuaJIT to prevent issues? | 193 | // Do I need to disable this when compiling for LuaJIT to prevent issues? |
194 | void initialize_allocator_function( Universe* U, lua_State* L) | 194 | void initialize_allocator_function( Universe* U, lua_State* L) |
195 | { | 195 | { |
196 | STACK_CHECK( L, 0); | 196 | STACK_CHECK_START_REL(L, 1); // settings |
197 | lua_getfield( L, -1, "allocator"); // settings allocator|nil|"protected" | 197 | lua_getfield( L, -1, "allocator"); // settings allocator|nil|"protected" |
198 | if( !lua_isnil( L, -1)) | 198 | if( !lua_isnil( L, -1)) |
199 | { | 199 | { |
@@ -232,7 +232,7 @@ void initialize_allocator_function( Universe* U, lua_State* L) | |||
232 | U->protected_allocator.definition.allocF = lua_getallocf( L, &U->protected_allocator.definition.allocUD); | 232 | U->protected_allocator.definition.allocF = lua_getallocf( L, &U->protected_allocator.definition.allocUD); |
233 | } | 233 | } |
234 | lua_pop( L, 1); // settings | 234 | lua_pop( L, 1); // settings |
235 | STACK_MID(L, 0); | 235 | STACK_CHECK(L, 1); |
236 | 236 | ||
237 | lua_getfield( L, -1, "internal_allocator"); // settings "libc"|"allocator" | 237 | lua_getfield( L, -1, "internal_allocator"); // settings "libc"|"allocator" |
238 | { | 238 | { |
@@ -248,7 +248,7 @@ void initialize_allocator_function( Universe* U, lua_State* L) | |||
248 | } | 248 | } |
249 | } | 249 | } |
250 | lua_pop( L, 1); // settings | 250 | lua_pop( L, 1); // settings |
251 | STACK_END( L, 0); | 251 | STACK_CHECK( L, 1); |
252 | } | 252 | } |
253 | 253 | ||
254 | void cleanup_allocator_function( Universe* U, lua_State* L) | 254 | void cleanup_allocator_function( Universe* U, lua_State* L) |
@@ -335,7 +335,7 @@ static char const* luaG_pushFQN( lua_State* L, int t, int last, size_t* length) | |||
335 | { | 335 | { |
336 | int i = 1; | 336 | int i = 1; |
337 | luaL_Buffer b; | 337 | luaL_Buffer b; |
338 | STACK_CHECK( L, 0); | 338 | STACK_CHECK_START_REL(L, 0); |
339 | // Lua 5.4 pushes &b as light userdata on the stack. be aware of it... | 339 | // Lua 5.4 pushes &b as light userdata on the stack. be aware of it... |
340 | luaL_buffinit( L, &b); // ... {} ... &b? | 340 | luaL_buffinit( L, &b); // ... {} ... &b? |
341 | for( ; i < last; ++ i) | 341 | for( ; i < last; ++ i) |
@@ -351,7 +351,7 @@ static char const* luaG_pushFQN( lua_State* L, int t, int last, size_t* length) | |||
351 | } | 351 | } |
352 | // &b is popped at that point (-> replaced by the result) | 352 | // &b is popped at that point (-> replaced by the result) |
353 | luaL_pushresult( &b); // ... {} ... "<result>" | 353 | luaL_pushresult( &b); // ... {} ... "<result>" |
354 | STACK_END( L, 1); | 354 | STACK_CHECK( L, 1); |
355 | return lua_tolstring( L, -1, length); | 355 | return lua_tolstring( L, -1, length); |
356 | } | 356 | } |
357 | 357 | ||
@@ -376,7 +376,7 @@ static void update_lookup_entry( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* | |||
376 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "update_lookup_entry()\n" INDENT_END)); | 376 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "update_lookup_entry()\n" INDENT_END)); |
377 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); | 377 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); |
378 | 378 | ||
379 | STACK_CHECK( L, 0); | 379 | STACK_CHECK_START_REL(L, 0); |
380 | // first, raise an error if the function is already known | 380 | // first, raise an error if the function is already known |
381 | lua_pushvalue( L, -1); // ... {bfc} k o o | 381 | lua_pushvalue( L, -1); // ... {bfc} k o o |
382 | lua_rawget( L, dest); // ... {bfc} k o name? | 382 | lua_rawget( L, dest); // ... {bfc} k o name? |
@@ -433,7 +433,7 @@ static void update_lookup_entry( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* | |||
433 | lua_rawseti( L, fqn, _depth); // ... {bfc} k | 433 | lua_rawseti( L, fqn, _depth); // ... {bfc} k |
434 | } | 434 | } |
435 | -- _depth; | 435 | -- _depth; |
436 | STACK_END( L, -1); | 436 | STACK_CHECK( L, -1); |
437 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); | 437 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); |
438 | } | 438 | } |
439 | 439 | ||
@@ -451,13 +451,13 @@ static void populate_func_lookup_table_recur( DEBUGSPEW_PARAM_COMMA( Universe* U | |||
451 | 451 | ||
452 | STACK_GROW( L, 6); | 452 | STACK_GROW( L, 6); |
453 | // slot _i contains a table where we search for functions (or a full userdata with a metatable) | 453 | // slot _i contains a table where we search for functions (or a full userdata with a metatable) |
454 | STACK_CHECK( L, 0); // ... {_i} | 454 | STACK_CHECK_START_REL(L, 0); // ... {_i} |
455 | 455 | ||
456 | // if object is a userdata, replace it by its metatable | 456 | // if object is a userdata, replace it by its metatable |
457 | if( lua_type( L, _i) == LUA_TUSERDATA) | 457 | if( lua_type( L, _i) == LUA_TUSERDATA) |
458 | { | 458 | { |
459 | lua_getmetatable( L, _i); // ... {_i} mt | 459 | lua_getmetatable( L, _i); // ... {_i} mt |
460 | lua_replace( L, _i); // ... {_i} | 460 | lua_replace( L, _i); // ... {_i} |
461 | } | 461 | } |
462 | 462 | ||
463 | // if table is already visited, we are done | 463 | // if table is already visited, we are done |
@@ -465,7 +465,7 @@ static void populate_func_lookup_table_recur( DEBUGSPEW_PARAM_COMMA( Universe* U | |||
465 | lua_rawget( L, cache); // ... {_i} nil|n | 465 | lua_rawget( L, cache); // ... {_i} nil|n |
466 | visit_count = lua_tointeger( L, -1); // 0 if nil, else n | 466 | visit_count = lua_tointeger( L, -1); // 0 if nil, else n |
467 | lua_pop( L, 1); // ... {_i} | 467 | lua_pop( L, 1); // ... {_i} |
468 | STACK_MID( L, 0); | 468 | STACK_CHECK( L, 0); |
469 | if( visit_count > 0) | 469 | if( visit_count > 0) |
470 | { | 470 | { |
471 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "already visited\n" INDENT_END)); | 471 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "already visited\n" INDENT_END)); |
@@ -477,7 +477,7 @@ static void populate_func_lookup_table_recur( DEBUGSPEW_PARAM_COMMA( Universe* U | |||
477 | lua_pushvalue( L, _i); // ... {_i} {} | 477 | lua_pushvalue( L, _i); // ... {_i} {} |
478 | lua_pushinteger( L, visit_count + 1); // ... {_i} {} 1 | 478 | lua_pushinteger( L, visit_count + 1); // ... {_i} {} 1 |
479 | lua_rawset( L, cache); // ... {_i} | 479 | lua_rawset( L, cache); // ... {_i} |
480 | STACK_MID( L, 0); | 480 | STACK_CHECK( L, 0); |
481 | 481 | ||
482 | // this table is at breadth_first_cache index | 482 | // this table is at breadth_first_cache index |
483 | lua_newtable( L); // ... {_i} {bfc} | 483 | lua_newtable( L); // ... {_i} {bfc} |
@@ -515,7 +515,7 @@ static void populate_func_lookup_table_recur( DEBUGSPEW_PARAM_COMMA( Universe* U | |||
515 | { | 515 | { |
516 | lua_pop( L, 1); // ... {_i} {bfc} k | 516 | lua_pop( L, 1); // ... {_i} {bfc} k |
517 | } | 517 | } |
518 | STACK_MID( L, 2); | 518 | STACK_CHECK( L, 2); |
519 | } | 519 | } |
520 | // now process the tables we encountered at that depth | 520 | // now process the tables we encountered at that depth |
521 | ++ _depth; | 521 | ++ _depth; |
@@ -546,7 +546,7 @@ static void populate_func_lookup_table_recur( DEBUGSPEW_PARAM_COMMA( Universe* U | |||
546 | lua_rawseti( L, fqn, _depth); // ... {_i} {bfc} k {} | 546 | lua_rawseti( L, fqn, _depth); // ... {_i} {bfc} k {} |
547 | populate_func_lookup_table_recur( DEBUGSPEW_PARAM_COMMA( U) L, _ctx_base, lua_gettop( L), _depth); | 547 | populate_func_lookup_table_recur( DEBUGSPEW_PARAM_COMMA( U) L, _ctx_base, lua_gettop( L), _depth); |
548 | lua_pop( L, 1); // ... {_i} {bfc} k | 548 | lua_pop( L, 1); // ... {_i} {bfc} k |
549 | STACK_MID( L, 2); | 549 | STACK_CHECK( L, 2); |
550 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); | 550 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); |
551 | } | 551 | } |
552 | // remove table name from fqn stack | 552 | // remove table name from fqn stack |
@@ -555,7 +555,7 @@ static void populate_func_lookup_table_recur( DEBUGSPEW_PARAM_COMMA( Universe* U | |||
555 | -- _depth; | 555 | -- _depth; |
556 | // we are done with our cache | 556 | // we are done with our cache |
557 | lua_pop( L, 1); // ... {_i} | 557 | lua_pop( L, 1); // ... {_i} |
558 | STACK_END( L, 0); | 558 | STACK_CHECK( L, 0); |
559 | // we are done // ... {_i} {bfc} | 559 | // we are done // ... {_i} {bfc} |
560 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); | 560 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); |
561 | } | 561 | } |
@@ -572,9 +572,9 @@ void populate_func_lookup_table( lua_State* L, int _i, char const* name_) | |||
572 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%p: populate_func_lookup_table('%s')\n" INDENT_END, L, name_ ? name_ : "nullptr")); | 572 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%p: populate_func_lookup_table('%s')\n" INDENT_END, L, name_ ? name_ : "nullptr")); |
573 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); | 573 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); |
574 | STACK_GROW( L, 3); | 574 | STACK_GROW( L, 3); |
575 | STACK_CHECK( L, 0); | 575 | STACK_CHECK_START_REL(L, 0); |
576 | LOOKUP_REGKEY.query_registry(L); // {} | 576 | LOOKUP_REGKEY.query_registry(L); // {} |
577 | STACK_MID( L, 1); | 577 | STACK_CHECK( L, 1); |
578 | ASSERT_L( lua_istable( L, -1)); | 578 | ASSERT_L( lua_istable( L, -1)); |
579 | if( lua_type( L, in_base) == LUA_TFUNCTION) // for example when a module is a simple function | 579 | if( lua_type( L, in_base) == LUA_TFUNCTION) // for example when a module is a simple function |
580 | { | 580 | { |
@@ -592,7 +592,7 @@ void populate_func_lookup_table( lua_State* L, int _i, char const* name_) | |||
592 | lua_newtable( L); // {} {fqn} | 592 | lua_newtable( L); // {} {fqn} |
593 | if( name_) | 593 | if( name_) |
594 | { | 594 | { |
595 | STACK_MID( L, 2); | 595 | STACK_CHECK( L, 2); |
596 | lua_pushstring( L, name_); // {} {fqn} "name" | 596 | lua_pushstring( L, name_); // {} {fqn} "name" |
597 | // generate a name, and if we already had one name, keep whichever is the shorter | 597 | // generate a name, and if we already had one name, keep whichever is the shorter |
598 | lua_pushvalue( L, in_base); // {} {fqn} "name" t | 598 | lua_pushvalue( L, in_base); // {} {fqn} "name" t |
@@ -600,7 +600,7 @@ void populate_func_lookup_table( lua_State* L, int _i, char const* name_) | |||
600 | // don't forget to store the name at the bottom of the fqn stack | 600 | // don't forget to store the name at the bottom of the fqn stack |
601 | ++ start_depth; | 601 | ++ start_depth; |
602 | lua_rawseti( L, -2, start_depth); // {} {fqn} | 602 | lua_rawseti( L, -2, start_depth); // {} {fqn} |
603 | STACK_MID( L, 2); | 603 | STACK_CHECK( L, 2); |
604 | } | 604 | } |
605 | // retrieve the cache, create it if we haven't done it yet | 605 | // retrieve the cache, create it if we haven't done it yet |
606 | LOOKUPCACHE_REGKEY.query_registry(L); // {} {fqn} {cache}? | 606 | LOOKUPCACHE_REGKEY.query_registry(L); // {} {fqn} {cache}? |
@@ -609,7 +609,7 @@ void populate_func_lookup_table( lua_State* L, int _i, char const* name_) | |||
609 | lua_pop( L, 1); // {} {fqn} | 609 | lua_pop( L, 1); // {} {fqn} |
610 | lua_newtable( L); // {} {fqn} {cache} | 610 | lua_newtable( L); // {} {fqn} {cache} |
611 | LOOKUPCACHE_REGKEY.set_registry(L, [](lua_State* L) { lua_pushvalue(L, -2); }); | 611 | LOOKUPCACHE_REGKEY.set_registry(L, [](lua_State* L) { lua_pushvalue(L, -2); }); |
612 | STACK_MID( L, 3); | 612 | STACK_CHECK( L, 3); |
613 | } | 613 | } |
614 | // process everything we find in that table, filling in lookup data for all functions and tables we see there | 614 | // process everything we find in that table, filling in lookup data for all functions and tables we see there |
615 | populate_func_lookup_table_recur( DEBUGSPEW_PARAM_COMMA( U) L, ctx_base, in_base, start_depth); | 615 | populate_func_lookup_table_recur( DEBUGSPEW_PARAM_COMMA( U) L, ctx_base, in_base, start_depth); |
@@ -620,7 +620,7 @@ void populate_func_lookup_table( lua_State* L, int _i, char const* name_) | |||
620 | lua_pop( L, 1); // | 620 | lua_pop( L, 1); // |
621 | (void) luaL_error( L, "unsupported module type %s", lua_typename( L, lua_type( L, in_base))); | 621 | (void) luaL_error( L, "unsupported module type %s", lua_typename( L, lua_type( L, in_base))); |
622 | } | 622 | } |
623 | STACK_END( L, 0); | 623 | STACK_CHECK( L, 0); |
624 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); | 624 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); |
625 | } | 625 | } |
626 | 626 | ||
@@ -640,14 +640,14 @@ static lua_Integer get_mt_id( Universe* U, lua_State* L, int i) | |||
640 | 640 | ||
641 | STACK_GROW( L, 3); | 641 | STACK_GROW( L, 3); |
642 | 642 | ||
643 | STACK_CHECK( L, 0); | 643 | STACK_CHECK_START_REL(L, 0); |
644 | push_registry_subtable( L, REG_MTID); // ... _R[REG_MTID] | 644 | push_registry_subtable( L, REG_MTID); // ... _R[REG_MTID] |
645 | lua_pushvalue( L, i); // ... _R[REG_MTID] {mt} | 645 | lua_pushvalue( L, i); // ... _R[REG_MTID] {mt} |
646 | lua_rawget( L, -2); // ... _R[REG_MTID] mtk? | 646 | lua_rawget( L, -2); // ... _R[REG_MTID] mtk? |
647 | 647 | ||
648 | id = lua_tointeger( L, -1); // 0 for nil | 648 | id = lua_tointeger( L, -1); // 0 for nil |
649 | lua_pop( L, 1); // ... _R[REG_MTID] | 649 | lua_pop( L, 1); // ... _R[REG_MTID] |
650 | STACK_MID( L, 1); | 650 | STACK_CHECK( L, 1); |
651 | 651 | ||
652 | if( id == 0) | 652 | if( id == 0) |
653 | { | 653 | { |
@@ -667,7 +667,7 @@ static lua_Integer get_mt_id( Universe* U, lua_State* L, int i) | |||
667 | } | 667 | } |
668 | lua_pop( L, 1); // ... | 668 | lua_pop( L, 1); // ... |
669 | 669 | ||
670 | STACK_END( L, 0); | 670 | STACK_CHECK( L, 0); |
671 | 671 | ||
672 | return id; | 672 | return id; |
673 | } | 673 | } |
@@ -699,7 +699,7 @@ static char const* find_lookup_name(lua_State* L, int i, LookupMode mode_, char | |||
699 | DEBUGSPEW_CODE( Universe* const U = universe_get( L)); | 699 | DEBUGSPEW_CODE( Universe* const U = universe_get( L)); |
700 | char const* fqn; | 700 | char const* fqn; |
701 | ASSERT_L( lua_isfunction( L, i) || lua_istable( L, i)); // ... v ... | 701 | ASSERT_L( lua_isfunction( L, i) || lua_istable( L, i)); // ... v ... |
702 | STACK_CHECK( L, 0); | 702 | STACK_CHECK_START_REL(L, 0); |
703 | STACK_GROW( L, 3); // up to 3 slots are necessary on error | 703 | STACK_GROW( L, 3); // up to 3 slots are necessary on error |
704 | if( mode_ == eLM_FromKeeper) | 704 | if( mode_ == eLM_FromKeeper) |
705 | { | 705 | { |
@@ -720,7 +720,7 @@ static char const* find_lookup_name(lua_State* L, int i, LookupMode mode_, char | |||
720 | { | 720 | { |
721 | // fetch the name from the source state's lookup table | 721 | // fetch the name from the source state's lookup table |
722 | LOOKUP_REGKEY.query_registry(L); // ... v ... {} | 722 | LOOKUP_REGKEY.query_registry(L); // ... v ... {} |
723 | STACK_MID( L, 1); | 723 | STACK_CHECK( L, 1); |
724 | ASSERT_L( lua_istable( L, -1)); | 724 | ASSERT_L( lua_istable( L, -1)); |
725 | lua_pushvalue( L, i); // ... v ... {} v | 725 | lua_pushvalue( L, i); // ... v ... {} v |
726 | lua_rawget( L, -2); // ... v ... {} "f.q.n" | 726 | lua_rawget( L, -2); // ... v ... {} "f.q.n" |
@@ -729,7 +729,7 @@ static char const* find_lookup_name(lua_State* L, int i, LookupMode mode_, char | |||
729 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "function [C] %s \n" INDENT_END, fqn)); | 729 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "function [C] %s \n" INDENT_END, fqn)); |
730 | // popping doesn't invalidate the pointer since this is an interned string gotten from the lookup database | 730 | // popping doesn't invalidate the pointer since this is an interned string gotten from the lookup database |
731 | lua_pop( L, (mode_ == eLM_FromKeeper) ? 1 : 2); // ... v ... | 731 | lua_pop( L, (mode_ == eLM_FromKeeper) ? 1 : 2); // ... v ... |
732 | STACK_MID( L, 0); | 732 | STACK_CHECK( L, 0); |
733 | if (nullptr == fqn && !lua_istable(L, i)) // raise an error if we try to send an unknown function (but not for tables) | 733 | if (nullptr == fqn && !lua_istable(L, i)) // raise an error if we try to send an unknown function (but not for tables) |
734 | { | 734 | { |
735 | char const *from, *typewhat, *what, *gotchaA, *gotchaB; | 735 | char const *from, *typewhat, *what, *gotchaA, *gotchaB; |
@@ -758,7 +758,7 @@ static char const* find_lookup_name(lua_State* L, int i, LookupMode mode_, char | |||
758 | *len_ = 0; | 758 | *len_ = 0; |
759 | return nullptr; | 759 | return nullptr; |
760 | } | 760 | } |
761 | STACK_END( L, 0); | 761 | STACK_CHECK( L, 0); |
762 | return fqn; | 762 | return fqn; |
763 | } | 763 | } |
764 | 764 | ||
@@ -776,7 +776,7 @@ static bool lookup_table(lua_State* L2, lua_State* L, int i, LookupMode mode_, c | |||
776 | return false; | 776 | return false; |
777 | } | 777 | } |
778 | // push the equivalent table in the destination's stack, retrieved from the lookup table | 778 | // push the equivalent table in the destination's stack, retrieved from the lookup table |
779 | STACK_CHECK( L2, 0); // L // L2 | 779 | STACK_CHECK_START_REL(L2, 0); // L // L2 |
780 | STACK_GROW( L2, 3); // up to 3 slots are necessary on error | 780 | STACK_GROW( L2, 3); // up to 3 slots are necessary on error |
781 | switch( mode_) | 781 | switch( mode_) |
782 | { | 782 | { |
@@ -793,7 +793,7 @@ static bool lookup_table(lua_State* L2, lua_State* L, int i, LookupMode mode_, c | |||
793 | case eLM_LaneBody: | 793 | case eLM_LaneBody: |
794 | case eLM_FromKeeper: | 794 | case eLM_FromKeeper: |
795 | LOOKUP_REGKEY.query_registry(L2); // {} | 795 | LOOKUP_REGKEY.query_registry(L2); // {} |
796 | STACK_MID( L2, 1); | 796 | STACK_CHECK( L2, 1); |
797 | ASSERT_L( lua_istable( L2, -1)); | 797 | ASSERT_L( lua_istable( L2, -1)); |
798 | lua_pushlstring( L2, fqn, len); // {} "f.q.n" | 798 | lua_pushlstring( L2, fqn, len); // {} "f.q.n" |
799 | lua_rawget( L2, -2); // {} t | 799 | lua_rawget( L2, -2); // {} t |
@@ -802,7 +802,7 @@ static bool lookup_table(lua_State* L2, lua_State* L, int i, LookupMode mode_, c | |||
802 | if( lua_isnil( L2, -1) && mode_ == eLM_LaneBody) | 802 | if( lua_isnil( L2, -1) && mode_ == eLM_LaneBody) |
803 | { | 803 | { |
804 | lua_pop( L2, 2); // | 804 | lua_pop( L2, 2); // |
805 | STACK_MID( L2, 0); | 805 | STACK_CHECK( L2, 0); |
806 | return false; | 806 | return false; |
807 | } | 807 | } |
808 | else if( !lua_istable( L2, -1)) | 808 | else if( !lua_istable( L2, -1)) |
@@ -827,7 +827,7 @@ static bool lookup_table(lua_State* L2, lua_State* L, int i, LookupMode mode_, c | |||
827 | lua_remove( L2, -2); // t | 827 | lua_remove( L2, -2); // t |
828 | break; | 828 | break; |
829 | } | 829 | } |
830 | STACK_END( L2, 1); | 830 | STACK_CHECK( L2, 1); |
831 | return true; | 831 | return true; |
832 | } | 832 | } |
833 | 833 | ||
@@ -849,7 +849,7 @@ static bool push_cached_table(lua_State* L2, int L2_cache_i, lua_State* L, int i | |||
849 | 849 | ||
850 | ASSERT_L( L2_cache_i != 0); | 850 | ASSERT_L( L2_cache_i != 0); |
851 | STACK_GROW( L2, 3); | 851 | STACK_GROW( L2, 3); |
852 | STACK_CHECK( L2, 0); | 852 | STACK_CHECK_START_REL(L2, 0); |
853 | 853 | ||
854 | // We don't need to use the from state ('L') in ID since the life span | 854 | // We don't need to use the from state ('L') in ID since the life span |
855 | // is only for the duration of a copy (both states are locked). | 855 | // is only for the duration of a copy (both states are locked). |
@@ -868,7 +868,7 @@ static bool push_cached_table(lua_State* L2, int L2_cache_i, lua_State* L, int i | |||
868 | lua_pushvalue( L2, -2); // ... {} p {} | 868 | lua_pushvalue( L2, -2); // ... {} p {} |
869 | lua_rawset( L2, L2_cache_i); // ... {} | 869 | lua_rawset( L2, L2_cache_i); // ... {} |
870 | } | 870 | } |
871 | STACK_END( L2, 1); | 871 | STACK_CHECK( L2, 1); |
872 | ASSERT_L( lua_istable( L2, -1)); | 872 | ASSERT_L( lua_istable( L2, -1)); |
873 | return !not_found_in_cache; | 873 | return !not_found_in_cache; |
874 | } | 874 | } |
@@ -889,7 +889,7 @@ static int discover_object_name_recur( lua_State* L, int shortest_, int depth_) | |||
889 | return shortest_; | 889 | return shortest_; |
890 | } | 890 | } |
891 | STACK_GROW( L, 3); | 891 | STACK_GROW( L, 3); |
892 | STACK_CHECK( L, 0); | 892 | STACK_CHECK_START_REL(L, 0); |
893 | // stack top contains the table to search in | 893 | // stack top contains the table to search in |
894 | lua_pushvalue( L, -1); // o "r" {c} {fqn} ... {?} {?} | 894 | lua_pushvalue( L, -1); // o "r" {c} {fqn} ... {?} {?} |
895 | lua_rawget( L, cache); // o "r" {c} {fqn} ... {?} nil/1 | 895 | lua_rawget( L, cache); // o "r" {c} {fqn} ... {?} nil/1 |
@@ -910,14 +910,14 @@ static int discover_object_name_recur( lua_State* L, int shortest_, int depth_) | |||
910 | { | 910 | { |
911 | //char const *const strKey = (lua_type( L, -2) == LUA_TSTRING) ? lua_tostring( L, -2) : nullptr; // only for debugging | 911 | //char const *const strKey = (lua_type( L, -2) == LUA_TSTRING) ? lua_tostring( L, -2) : nullptr; // only for debugging |
912 | //lua_Number const numKey = (lua_type( L, -2) == LUA_TNUMBER) ? lua_tonumber( L, -2) : -6666; // only for debugging | 912 | //lua_Number const numKey = (lua_type( L, -2) == LUA_TNUMBER) ? lua_tonumber( L, -2) : -6666; // only for debugging |
913 | STACK_MID( L, 2); | 913 | STACK_CHECK( L, 2); |
914 | // append key name to fqn stack | 914 | // append key name to fqn stack |
915 | ++ depth_; | 915 | ++ depth_; |
916 | lua_pushvalue( L, -2); // o "r" {c} {fqn} ... {?} k v k | 916 | lua_pushvalue( L, -2); // o "r" {c} {fqn} ... {?} k v k |
917 | lua_rawseti( L, fqn, depth_); // o "r" {c} {fqn} ... {?} k v | 917 | lua_rawseti( L, fqn, depth_); // o "r" {c} {fqn} ... {?} k v |
918 | if( lua_rawequal( L, -1, what)) // is it what we are looking for? | 918 | if( lua_rawequal( L, -1, what)) // is it what we are looking for? |
919 | { | 919 | { |
920 | STACK_MID( L, 2); | 920 | STACK_CHECK( L, 2); |
921 | // update shortest name | 921 | // update shortest name |
922 | if( depth_ < shortest_) | 922 | if( depth_ < shortest_) |
923 | { | 923 | { |
@@ -927,7 +927,7 @@ static int discover_object_name_recur( lua_State* L, int shortest_, int depth_) | |||
927 | } | 927 | } |
928 | // no need to search further at this level | 928 | // no need to search further at this level |
929 | lua_pop( L, 2); // o "r" {c} {fqn} ... {?} | 929 | lua_pop( L, 2); // o "r" {c} {fqn} ... {?} |
930 | STACK_MID( L, 0); | 930 | STACK_CHECK( L, 0); |
931 | break; | 931 | break; |
932 | } | 932 | } |
933 | switch( lua_type( L, -1)) // o "r" {c} {fqn} ... {?} k v | 933 | switch( lua_type( L, -1)) // o "r" {c} {fqn} ... {?} k v |
@@ -936,7 +936,7 @@ static int discover_object_name_recur( lua_State* L, int shortest_, int depth_) | |||
936 | break; | 936 | break; |
937 | 937 | ||
938 | case LUA_TTABLE: // o "r" {c} {fqn} ... {?} k {} | 938 | case LUA_TTABLE: // o "r" {c} {fqn} ... {?} k {} |
939 | STACK_MID( L, 2); | 939 | STACK_CHECK( L, 2); |
940 | shortest_ = discover_object_name_recur( L, shortest_, depth_); | 940 | shortest_ = discover_object_name_recur( L, shortest_, depth_); |
941 | // search in the table's metatable too | 941 | // search in the table's metatable too |
942 | if( lua_getmetatable( L, -1)) // o "r" {c} {fqn} ... {?} k {} {mt} | 942 | if( lua_getmetatable( L, -1)) // o "r" {c} {fqn} ... {?} k {} {mt} |
@@ -953,7 +953,7 @@ static int discover_object_name_recur( lua_State* L, int shortest_, int depth_) | |||
953 | } | 953 | } |
954 | lua_pop( L, 1); // o "r" {c} {fqn} ... {?} k {} | 954 | lua_pop( L, 1); // o "r" {c} {fqn} ... {?} k {} |
955 | } | 955 | } |
956 | STACK_MID( L, 2); | 956 | STACK_CHECK( L, 2); |
957 | break; | 957 | break; |
958 | 958 | ||
959 | case LUA_TTHREAD: // o "r" {c} {fqn} ... {?} k T | 959 | case LUA_TTHREAD: // o "r" {c} {fqn} ... {?} k T |
@@ -961,7 +961,7 @@ static int discover_object_name_recur( lua_State* L, int shortest_, int depth_) | |||
961 | break; | 961 | break; |
962 | 962 | ||
963 | case LUA_TUSERDATA: // o "r" {c} {fqn} ... {?} k U | 963 | case LUA_TUSERDATA: // o "r" {c} {fqn} ... {?} k U |
964 | STACK_MID( L, 2); | 964 | STACK_CHECK( L, 2); |
965 | // search in the object's metatable (some modules are built that way) | 965 | // search in the object's metatable (some modules are built that way) |
966 | if( lua_getmetatable( L, -1)) // o "r" {c} {fqn} ... {?} k U {mt} | 966 | if( lua_getmetatable( L, -1)) // o "r" {c} {fqn} ... {?} k U {mt} |
967 | { | 967 | { |
@@ -977,7 +977,7 @@ static int discover_object_name_recur( lua_State* L, int shortest_, int depth_) | |||
977 | } | 977 | } |
978 | lua_pop( L, 1); // o "r" {c} {fqn} ... {?} k U | 978 | lua_pop( L, 1); // o "r" {c} {fqn} ... {?} k U |
979 | } | 979 | } |
980 | STACK_MID( L, 2); | 980 | STACK_CHECK( L, 2); |
981 | // search in the object's uservalues | 981 | // search in the object's uservalues |
982 | { | 982 | { |
983 | int uvi = 1; | 983 | int uvi = 1; |
@@ -999,7 +999,7 @@ static int discover_object_name_recur( lua_State* L, int shortest_, int depth_) | |||
999 | // when lua_getiuservalue() returned LUA_TNONE, it pushed a nil. pop it now | 999 | // when lua_getiuservalue() returned LUA_TNONE, it pushed a nil. pop it now |
1000 | lua_pop( L, 1); // o "r" {c} {fqn} ... {?} k U | 1000 | lua_pop( L, 1); // o "r" {c} {fqn} ... {?} k U |
1001 | } | 1001 | } |
1002 | STACK_MID( L, 2); | 1002 | STACK_CHECK( L, 2); |
1003 | break; | 1003 | break; |
1004 | } | 1004 | } |
1005 | // make ready for next iteration | 1005 | // make ready for next iteration |
@@ -1007,15 +1007,15 @@ static int discover_object_name_recur( lua_State* L, int shortest_, int depth_) | |||
1007 | // remove name from fqn stack | 1007 | // remove name from fqn stack |
1008 | lua_pushnil( L); // o "r" {c} {fqn} ... {?} k nil | 1008 | lua_pushnil( L); // o "r" {c} {fqn} ... {?} k nil |
1009 | lua_rawseti( L, fqn, depth_); // o "r" {c} {fqn} ... {?} k | 1009 | lua_rawseti( L, fqn, depth_); // o "r" {c} {fqn} ... {?} k |
1010 | STACK_MID( L, 1); | 1010 | STACK_CHECK( L, 1); |
1011 | -- depth_; | 1011 | -- depth_; |
1012 | } // o "r" {c} {fqn} ... {?} | 1012 | } // o "r" {c} {fqn} ... {?} |
1013 | STACK_MID( L, 0); | 1013 | STACK_CHECK( L, 0); |
1014 | // remove the visited table from the cache, in case a shorter path to the searched object exists | 1014 | // remove the visited table from the cache, in case a shorter path to the searched object exists |
1015 | lua_pushvalue( L, -1); // o "r" {c} {fqn} ... {?} {?} | 1015 | lua_pushvalue( L, -1); // o "r" {c} {fqn} ... {?} {?} |
1016 | lua_pushnil( L); // o "r" {c} {fqn} ... {?} {?} nil | 1016 | lua_pushnil( L); // o "r" {c} {fqn} ... {?} {?} nil |
1017 | lua_rawset( L, cache); // o "r" {c} {fqn} ... {?} | 1017 | lua_rawset( L, cache); // o "r" {c} {fqn} ... {?} |
1018 | STACK_END( L, 0); | 1018 | STACK_CHECK( L, 0); |
1019 | return shortest_; | 1019 | return shortest_; |
1020 | } | 1020 | } |
1021 | 1021 | ||
@@ -1040,7 +1040,7 @@ int luaG_nameof( lua_State* L) | |||
1040 | } | 1040 | } |
1041 | 1041 | ||
1042 | STACK_GROW( L, 4); | 1042 | STACK_GROW( L, 4); |
1043 | STACK_CHECK( L, 0); | 1043 | STACK_CHECK_START_REL(L, 0); |
1044 | // this slot will contain the shortest name we found when we are done | 1044 | // this slot will contain the shortest name we found when we are done |
1045 | lua_pushnil( L); // o nil | 1045 | lua_pushnil( L); // o nil |
1046 | // push a cache that will contain all already visited tables | 1046 | // push a cache that will contain all already visited tables |
@@ -1061,7 +1061,7 @@ int luaG_nameof( lua_State* L) | |||
1061 | (void) discover_object_name_recur( L, 6666, 1); | 1061 | (void) discover_object_name_recur( L, 6666, 1); |
1062 | } | 1062 | } |
1063 | lua_pop( L, 3); // o "result" | 1063 | lua_pop( L, 3); // o "result" |
1064 | STACK_END( L, 1); | 1064 | STACK_CHECK( L, 1); |
1065 | lua_pushstring( L, luaL_typename( L, 1)); // o "result" "type" | 1065 | lua_pushstring( L, luaL_typename( L, 1)); // o "result" "type" |
1066 | lua_replace( L, -3); // "type" "result" | 1066 | lua_replace( L, -3); // "type" "result" |
1067 | return 2; | 1067 | return 2; |
@@ -1077,7 +1077,7 @@ static void lookup_native_func(lua_State* L2, lua_State* L, int i, LookupMode mo | |||
1077 | size_t len; | 1077 | size_t len; |
1078 | char const* fqn = find_lookup_name( L, i, mode_, upName_, &len); | 1078 | char const* fqn = find_lookup_name( L, i, mode_, upName_, &len); |
1079 | // push the equivalent function in the destination's stack, retrieved from the lookup table | 1079 | // push the equivalent function in the destination's stack, retrieved from the lookup table |
1080 | STACK_CHECK( L2, 0); // L // L2 | 1080 | STACK_CHECK_START_REL(L2, 0); // L // L2 |
1081 | STACK_GROW( L2, 3); // up to 3 slots are necessary on error | 1081 | STACK_GROW( L2, 3); // up to 3 slots are necessary on error |
1082 | switch( mode_) | 1082 | switch( mode_) |
1083 | { | 1083 | { |
@@ -1094,7 +1094,7 @@ static void lookup_native_func(lua_State* L2, lua_State* L, int i, LookupMode mo | |||
1094 | case eLM_LaneBody: | 1094 | case eLM_LaneBody: |
1095 | case eLM_FromKeeper: | 1095 | case eLM_FromKeeper: |
1096 | LOOKUP_REGKEY.query_registry(L2); // {} | 1096 | LOOKUP_REGKEY.query_registry(L2); // {} |
1097 | STACK_MID( L2, 1); | 1097 | STACK_CHECK( L2, 1); |
1098 | ASSERT_L( lua_istable( L2, -1)); | 1098 | ASSERT_L( lua_istable( L2, -1)); |
1099 | lua_pushlstring( L2, fqn, len); // {} "f.q.n" | 1099 | lua_pushlstring( L2, fqn, len); // {} "f.q.n" |
1100 | lua_rawget( L2, -2); // {} f | 1100 | lua_rawget( L2, -2); // {} f |
@@ -1139,7 +1139,7 @@ static void lookup_native_func(lua_State* L2, lua_State* L, int i, LookupMode mo | |||
1139 | break; | 1139 | break; |
1140 | */ | 1140 | */ |
1141 | } | 1141 | } |
1142 | STACK_END( L2, 1); | 1142 | STACK_CHECK( L2, 1); |
1143 | } | 1143 | } |
1144 | 1144 | ||
1145 | 1145 | ||
@@ -1194,7 +1194,7 @@ static void copy_func(Universe* U, lua_State* L2, int L2_cache_i, lua_State* L, | |||
1194 | 1194 | ||
1195 | ASSERT_L( L2_cache_i != 0); // ... {cache} ... p | 1195 | ASSERT_L( L2_cache_i != 0); // ... {cache} ... p |
1196 | STACK_GROW( L, 2); | 1196 | STACK_GROW( L, 2); |
1197 | STACK_CHECK( L, 0); | 1197 | STACK_CHECK_START_REL(L, 0); |
1198 | 1198 | ||
1199 | 1199 | ||
1200 | // 'lua_dump()' needs the function at top of stack | 1200 | // 'lua_dump()' needs the function at top of stack |
@@ -1270,7 +1270,7 @@ static void copy_func(Universe* U, lua_State* L2, int L2_cache_i, lua_State* L, | |||
1270 | // cache[p] = function | 1270 | // cache[p] = function |
1271 | lua_rawset( L2, L2_cache_i); // ... {cache} ... function | 1271 | lua_rawset( L2, L2_cache_i); // ... {cache} ... function |
1272 | } | 1272 | } |
1273 | STACK_MID( L, 0); | 1273 | STACK_CHECK( L, 0); |
1274 | 1274 | ||
1275 | /* push over any upvalues; references to this function will come from | 1275 | /* push over any upvalues; references to this function will come from |
1276 | * cache so we don't end up in eternal loop. | 1276 | * cache so we don't end up in eternal loop. |
@@ -1311,7 +1311,7 @@ static void copy_func(Universe* U, lua_State* L2, int L2_cache_i, lua_State* L, | |||
1311 | } | 1311 | } |
1312 | // L2: function + 'n' upvalues (>=0) | 1312 | // L2: function + 'n' upvalues (>=0) |
1313 | 1313 | ||
1314 | STACK_MID( L, 0); | 1314 | STACK_CHECK( L, 0); |
1315 | 1315 | ||
1316 | // Set upvalues (originally set to 'nil' by 'lua_load') | 1316 | // Set upvalues (originally set to 'nil' by 'lua_load') |
1317 | { | 1317 | { |
@@ -1329,7 +1329,7 @@ static void copy_func(Universe* U, lua_State* L2, int L2_cache_i, lua_State* L, | |||
1329 | // with the function at the top of the stack // ... {cache} ... function | 1329 | // with the function at the top of the stack // ... {cache} ... function |
1330 | } | 1330 | } |
1331 | } | 1331 | } |
1332 | STACK_END( L, 0); | 1332 | STACK_CHECK( L, 0); |
1333 | } | 1333 | } |
1334 | 1334 | ||
1335 | /* | 1335 | /* |
@@ -1352,7 +1352,7 @@ static void copy_cached_func(Universe* U, lua_State* L2, int L2_cache_i, lua_Sta | |||
1352 | 1352 | ||
1353 | // L2_cache[id_str]= function | 1353 | // L2_cache[id_str]= function |
1354 | // | 1354 | // |
1355 | STACK_CHECK( L2, 0); | 1355 | STACK_CHECK_START_REL(L2, 0); |
1356 | 1356 | ||
1357 | // We don't need to use the from state ('L') in ID since the life span | 1357 | // We don't need to use the from state ('L') in ID since the life span |
1358 | // is only for the duration of a copy (both states are locked). | 1358 | // is only for the duration of a copy (both states are locked). |
@@ -1380,7 +1380,7 @@ static void copy_cached_func(Universe* U, lua_State* L2, int L2_cache_i, lua_Sta | |||
1380 | { | 1380 | { |
1381 | lua_remove( L2, -2); // ... {cache} ... function | 1381 | lua_remove( L2, -2); // ... {cache} ... function |
1382 | } | 1382 | } |
1383 | STACK_END( L2, 1); | 1383 | STACK_CHECK( L2, 1); |
1384 | ASSERT_L( lua_isfunction( L2, -1)); | 1384 | ASSERT_L( lua_isfunction( L2, -1)); |
1385 | } | 1385 | } |
1386 | else // function is native/LuaJIT: no need to cache | 1386 | else // function is native/LuaJIT: no need to cache |
@@ -1393,26 +1393,26 @@ static void copy_cached_func(Universe* U, lua_State* L2, int L2_cache_i, lua_Sta | |||
1393 | 1393 | ||
1394 | static bool push_cached_metatable(Universe* U, lua_State* L2, int L2_cache_i, lua_State* L, int i, LookupMode mode_, char const* upName_) | 1394 | static bool push_cached_metatable(Universe* U, lua_State* L2, int L2_cache_i, lua_State* L, int i, LookupMode mode_, char const* upName_) |
1395 | { | 1395 | { |
1396 | STACK_CHECK( L, 0); | 1396 | STACK_CHECK_START_REL(L, 0); |
1397 | if( lua_getmetatable( L, i)) // ... mt | 1397 | if( lua_getmetatable( L, i)) // ... mt |
1398 | { | 1398 | { |
1399 | lua_Integer const mt_id = get_mt_id( U, L, -1); // Unique id for the metatable | 1399 | lua_Integer const mt_id = get_mt_id( U, L, -1); // Unique id for the metatable |
1400 | 1400 | ||
1401 | STACK_CHECK( L2, 0); | 1401 | STACK_CHECK_START_REL(L2, 0); |
1402 | STACK_GROW( L2, 4); | 1402 | STACK_GROW( L2, 4); |
1403 | // do we already know this metatable? | 1403 | // do we already know this metatable? |
1404 | push_registry_subtable( L2, REG_MTID); // _R[REG_MTID] | 1404 | push_registry_subtable( L2, REG_MTID); // _R[REG_MTID] |
1405 | lua_pushinteger( L2, mt_id); // _R[REG_MTID] id | 1405 | lua_pushinteger( L2, mt_id); // _R[REG_MTID] id |
1406 | lua_rawget( L2, -2); // _R[REG_MTID] mt? | 1406 | lua_rawget( L2, -2); // _R[REG_MTID] mt? |
1407 | 1407 | ||
1408 | STACK_MID( L2, 2); | 1408 | STACK_CHECK( L2, 2); |
1409 | 1409 | ||
1410 | if( lua_isnil( L2, -1)) | 1410 | if( lua_isnil( L2, -1)) |
1411 | { // L2 did not know the metatable | 1411 | { // L2 did not know the metatable |
1412 | lua_pop( L2, 1); // _R[REG_MTID] | 1412 | lua_pop( L2, 1); // _R[REG_MTID] |
1413 | if( inter_copy_one( U, L2, L2_cache_i, L, lua_gettop( L), VT_METATABLE, mode_, upName_)) // _R[REG_MTID] mt | 1413 | if( inter_copy_one( U, L2, L2_cache_i, L, lua_gettop( L), VT_METATABLE, mode_, upName_)) // _R[REG_MTID] mt |
1414 | { | 1414 | { |
1415 | STACK_MID( L2, 2); | 1415 | STACK_CHECK( L2, 2); |
1416 | // mt_id -> metatable | 1416 | // mt_id -> metatable |
1417 | lua_pushinteger( L2, mt_id); // _R[REG_MTID] mt id | 1417 | lua_pushinteger( L2, mt_id); // _R[REG_MTID] mt id |
1418 | lua_pushvalue( L2, -2); // _R[REG_MTID] mt id mt | 1418 | lua_pushvalue( L2, -2); // _R[REG_MTID] mt id mt |
@@ -1427,16 +1427,16 @@ static bool push_cached_metatable(Universe* U, lua_State* L2, int L2_cache_i, lu | |||
1427 | { | 1427 | { |
1428 | (void) luaL_error( L, "Error copying a metatable"); | 1428 | (void) luaL_error( L, "Error copying a metatable"); |
1429 | } | 1429 | } |
1430 | STACK_MID( L2, 2); | 1430 | STACK_CHECK( L2, 2); |
1431 | } | 1431 | } |
1432 | lua_remove( L2, -2); // mt | 1432 | lua_remove( L2, -2); // mt |
1433 | 1433 | ||
1434 | lua_pop( L, 1); // ... | 1434 | lua_pop( L, 1); // ... |
1435 | STACK_END( L2, 1); | 1435 | STACK_CHECK( L2, 1); |
1436 | STACK_MID( L, 0); | 1436 | STACK_CHECK( L, 0); |
1437 | return true; | 1437 | return true; |
1438 | } | 1438 | } |
1439 | STACK_END( L, 0); | 1439 | STACK_CHECK( L, 0); |
1440 | return false; | 1440 | return false; |
1441 | } | 1441 | } |
1442 | 1442 | ||
@@ -1515,27 +1515,27 @@ static bool copyclone(Universe* U, lua_State* L2, int L2_cache_i, lua_State* L, | |||
1515 | void* const source = lua_touserdata( L, source_i_); | 1515 | void* const source = lua_touserdata( L, source_i_); |
1516 | source_i_ = lua_absindex( L, source_i_); | 1516 | source_i_ = lua_absindex( L, source_i_); |
1517 | 1517 | ||
1518 | STACK_CHECK( L, 0); // L (source) // L2 (destination) | 1518 | STACK_CHECK_START_REL(L, 0); // L (source) // L2 (destination) |
1519 | STACK_CHECK( L2, 0); | 1519 | STACK_CHECK_START_REL(L2, 0); |
1520 | 1520 | ||
1521 | // Check if the source was already cloned during this copy | 1521 | // Check if the source was already cloned during this copy |
1522 | lua_pushlightuserdata( L2, source); // ... source | 1522 | lua_pushlightuserdata( L2, source); // ... source |
1523 | lua_rawget( L2, L2_cache_i); // ... clone? | 1523 | lua_rawget( L2, L2_cache_i); // ... clone? |
1524 | if ( !lua_isnil( L2, -1)) | 1524 | if ( !lua_isnil( L2, -1)) |
1525 | { | 1525 | { |
1526 | STACK_MID( L2, 1); | 1526 | STACK_CHECK( L2, 1); |
1527 | return true; | 1527 | return true; |
1528 | } | 1528 | } |
1529 | else | 1529 | else |
1530 | { | 1530 | { |
1531 | lua_pop( L2, 1); // ... | 1531 | lua_pop( L2, 1); // ... |
1532 | } | 1532 | } |
1533 | STACK_MID( L2, 0); | 1533 | STACK_CHECK( L2, 0); |
1534 | 1534 | ||
1535 | // no metatable? -> not clonable | 1535 | // no metatable? -> not clonable |
1536 | if( !lua_getmetatable( L, source_i_)) // ... mt? | 1536 | if( !lua_getmetatable( L, source_i_)) // ... mt? |
1537 | { | 1537 | { |
1538 | STACK_MID( L, 0); | 1538 | STACK_CHECK( L, 0); |
1539 | return false; | 1539 | return false; |
1540 | } | 1540 | } |
1541 | 1541 | ||
@@ -1544,7 +1544,7 @@ static bool copyclone(Universe* U, lua_State* L2, int L2_cache_i, lua_State* L, | |||
1544 | if( lua_isnil( L, -1)) | 1544 | if( lua_isnil( L, -1)) |
1545 | { | 1545 | { |
1546 | lua_pop( L, 2); // ... | 1546 | lua_pop( L, 2); // ... |
1547 | STACK_MID( L, 0); | 1547 | STACK_CHECK( L, 0); |
1548 | return false; | 1548 | return false; |
1549 | } | 1549 | } |
1550 | 1550 | ||
@@ -1578,7 +1578,7 @@ static bool copyclone(Universe* U, lua_State* L2, int L2_cache_i, lua_State* L, | |||
1578 | ASSERT_L( lua_istable( L2, -1)); | 1578 | ASSERT_L( lua_istable( L2, -1)); |
1579 | lua_setmetatable( L2, -2); // ... u | 1579 | lua_setmetatable( L2, -2); // ... u |
1580 | } | 1580 | } |
1581 | STACK_MID( L2, 1); | 1581 | STACK_CHECK( L2, 1); |
1582 | } | 1582 | } |
1583 | else | 1583 | else |
1584 | { | 1584 | { |
@@ -1597,7 +1597,7 @@ static bool copyclone(Universe* U, lua_State* L2, int L2_cache_i, lua_State* L, | |||
1597 | while( uvi > 0) | 1597 | while( uvi > 0) |
1598 | { | 1598 | { |
1599 | inter_copy_one( U, L2, L2_cache_i, L, lua_absindex( L, -1), VT_NORMAL, mode_, upName_); // ... u uv | 1599 | inter_copy_one( U, L2, L2_cache_i, L, lua_absindex( L, -1), VT_NORMAL, mode_, upName_); // ... u uv |
1600 | lua_pop( L, 1); // ... mt __lanesclone [uv]* | 1600 | lua_pop( L, 1); // ... mt __lanesclone [uv]* |
1601 | // this pops the value from the stack | 1601 | // this pops the value from the stack |
1602 | lua_setiuservalue( L2, -2, uvi); // ... u | 1602 | lua_setiuservalue( L2, -2, uvi); // ... u |
1603 | -- uvi; | 1603 | -- uvi; |
@@ -1607,26 +1607,26 @@ static bool copyclone(Universe* U, lua_State* L2, int L2_cache_i, lua_State* L, | |||
1607 | { | 1607 | { |
1608 | lua_pop( L2, 1); // ... userdata_clone_sentinel | 1608 | lua_pop( L2, 1); // ... userdata_clone_sentinel |
1609 | } | 1609 | } |
1610 | STACK_MID( L2, 1); | 1610 | STACK_CHECK( L2, 1); |
1611 | STACK_MID( L, 2); | 1611 | STACK_CHECK( L, 2); |
1612 | // call cloning function in source state to perform the actual memory cloning | 1612 | // call cloning function in source state to perform the actual memory cloning |
1613 | lua_pushlightuserdata( L, clone); // ... mt __lanesclone clone | 1613 | lua_pushlightuserdata( L, clone); // ... mt __lanesclone clone |
1614 | lua_pushlightuserdata( L, source); // ... mt __lanesclone clone source | 1614 | lua_pushlightuserdata( L, source); // ... mt __lanesclone clone source |
1615 | lua_pushinteger( L, userdata_size); // ... mt __lanesclone clone source size | 1615 | lua_pushinteger( L, userdata_size); // ... mt __lanesclone clone source size |
1616 | lua_call( L, 3, 0); // ... mt | 1616 | lua_call( L, 3, 0); // ... mt |
1617 | STACK_MID( L, 1); | 1617 | STACK_CHECK( L, 1); |
1618 | } | 1618 | } |
1619 | 1619 | ||
1620 | STACK_END( L2, 1); | 1620 | STACK_CHECK( L2, 1); |
1621 | lua_pop( L, 1); // ... | 1621 | lua_pop( L, 1); // ... |
1622 | STACK_END( L, 0); | 1622 | STACK_CHECK( L, 0); |
1623 | return true; | 1623 | return true; |
1624 | } | 1624 | } |
1625 | 1625 | ||
1626 | static bool inter_copy_userdata(Universe* U, lua_State* L2, int L2_cache_i, lua_State* L, int i, enum e_vt vt, LookupMode mode_, char const* upName_) | 1626 | static bool inter_copy_userdata(Universe* U, lua_State* L2, int L2_cache_i, lua_State* L, int i, enum e_vt vt, LookupMode mode_, char const* upName_) |
1627 | { | 1627 | { |
1628 | STACK_CHECK( L, 0); | 1628 | STACK_CHECK_START_REL(L, 0); |
1629 | STACK_CHECK( L2, 0); | 1629 | STACK_CHECK_START_REL(L2, 0); |
1630 | if( vt == VT_KEY) | 1630 | if( vt == VT_KEY) |
1631 | { | 1631 | { |
1632 | return false; | 1632 | return false; |
@@ -1635,25 +1635,25 @@ static bool inter_copy_userdata(Universe* U, lua_State* L2, int L2_cache_i, lua_ | |||
1635 | // try clonable userdata first | 1635 | // try clonable userdata first |
1636 | if( copyclone( U, L2, L2_cache_i, L, i, mode_, upName_)) | 1636 | if( copyclone( U, L2, L2_cache_i, L, i, mode_, upName_)) |
1637 | { | 1637 | { |
1638 | STACK_MID( L, 0); | 1638 | STACK_CHECK( L, 0); |
1639 | STACK_MID( L2, 1); | 1639 | STACK_CHECK( L2, 1); |
1640 | return true; | 1640 | return true; |
1641 | } | 1641 | } |
1642 | 1642 | ||
1643 | STACK_MID( L, 0); | 1643 | STACK_CHECK( L, 0); |
1644 | STACK_MID( L2, 0); | 1644 | STACK_CHECK( L2, 0); |
1645 | 1645 | ||
1646 | // Allow only deep userdata entities to be copied across | 1646 | // Allow only deep userdata entities to be copied across |
1647 | DEBUGSPEW_CODE( fprintf( stderr, "USERDATA\n")); | 1647 | DEBUGSPEW_CODE( fprintf( stderr, "USERDATA\n")); |
1648 | if( copydeep( U, L2, L2_cache_i, L, i, mode_, upName_)) | 1648 | if( copydeep( U, L2, L2_cache_i, L, i, mode_, upName_)) |
1649 | { | 1649 | { |
1650 | STACK_MID( L, 0); | 1650 | STACK_CHECK( L, 0); |
1651 | STACK_MID( L2, 1); | 1651 | STACK_CHECK( L2, 1); |
1652 | return true; | 1652 | return true; |
1653 | } | 1653 | } |
1654 | 1654 | ||
1655 | STACK_MID( L, 0); | 1655 | STACK_CHECK( L, 0); |
1656 | STACK_MID( L2, 0); | 1656 | STACK_CHECK( L2, 0); |
1657 | 1657 | ||
1658 | // Not a deep or clonable full userdata | 1658 | // Not a deep or clonable full userdata |
1659 | if( U->demoteFullUserdata) // attempt demotion to light userdata | 1659 | if( U->demoteFullUserdata) // attempt demotion to light userdata |
@@ -1666,8 +1666,8 @@ static bool inter_copy_userdata(Universe* U, lua_State* L2, int L2_cache_i, lua_ | |||
1666 | (void) luaL_error( L, "can't copy non-deep full userdata across lanes"); | 1666 | (void) luaL_error( L, "can't copy non-deep full userdata across lanes"); |
1667 | } | 1667 | } |
1668 | 1668 | ||
1669 | STACK_END( L2, 1); | 1669 | STACK_CHECK( L2, 1); |
1670 | STACK_END( L, 0); | 1670 | STACK_CHECK( L, 0); |
1671 | return true; | 1671 | return true; |
1672 | } | 1672 | } |
1673 | 1673 | ||
@@ -1678,8 +1678,8 @@ static bool inter_copy_function(Universe* U, lua_State* L2, int L2_cache_i, lua_ | |||
1678 | return false; | 1678 | return false; |
1679 | } | 1679 | } |
1680 | 1680 | ||
1681 | STACK_CHECK( L, 0); // L (source) // L2 (destination) | 1681 | STACK_CHECK_START_REL(L, 0); // L (source) // L2 (destination) |
1682 | STACK_CHECK( L2, 0); | 1682 | STACK_CHECK_START_REL(L2, 0); |
1683 | DEBUGSPEW_CODE( fprintf( stderr, "FUNCTION %s\n", upName_)); | 1683 | DEBUGSPEW_CODE( fprintf( stderr, "FUNCTION %s\n", upName_)); |
1684 | 1684 | ||
1685 | if( lua_tocfunction( L, source_i_) == userdata_clone_sentinel) // we are actually copying a clonable full userdata from a keeper | 1685 | if( lua_tocfunction( L, source_i_) == userdata_clone_sentinel) // we are actually copying a clonable full userdata from a keeper |
@@ -1697,8 +1697,8 @@ static bool inter_copy_function(Universe* U, lua_State* L2, int L2_cache_i, lua_ | |||
1697 | if( !lua_isnil( L2, -1)) | 1697 | if( !lua_isnil( L2, -1)) |
1698 | { | 1698 | { |
1699 | lua_pop( L, 1); // ... | 1699 | lua_pop( L, 1); // ... |
1700 | STACK_MID( L, 0); | 1700 | STACK_CHECK( L, 0); |
1701 | STACK_MID( L2, 1); | 1701 | STACK_CHECK( L2, 1); |
1702 | return true; | 1702 | return true; |
1703 | } | 1703 | } |
1704 | lua_pop( L2, 1); // ... | 1704 | lua_pop( L2, 1); // ... |
@@ -1717,7 +1717,7 @@ static bool inter_copy_function(Universe* U, lua_State* L2, int L2_cache_i, lua_ | |||
1717 | // when lua_getiuservalue() returned LUA_TNONE, it pushed a nil. pop it now | 1717 | // when lua_getiuservalue() returned LUA_TNONE, it pushed a nil. pop it now |
1718 | lua_pop( L, 1); // ... u [uv]* | 1718 | lua_pop( L, 1); // ... u [uv]* |
1719 | -- uvi; | 1719 | -- uvi; |
1720 | STACK_MID( L, uvi + 1); | 1720 | STACK_CHECK( L, uvi + 1); |
1721 | // create the clone userdata with the required number of uservalue slots | 1721 | // create the clone userdata with the required number of uservalue slots |
1722 | clone = lua_newuserdatauv( L2, userdata_size, uvi); // ... mt u | 1722 | clone = lua_newuserdatauv( L2, userdata_size, uvi); // ... mt u |
1723 | // add it in the cache | 1723 | // add it in the cache |
@@ -1738,8 +1738,8 @@ static bool inter_copy_function(Universe* U, lua_State* L2, int L2_cache_i, lua_ | |||
1738 | } | 1738 | } |
1739 | // when we are done, all uservalues are popped from the stack, we can pop the source as well | 1739 | // when we are done, all uservalues are popped from the stack, we can pop the source as well |
1740 | lua_pop( L, 1); // ... | 1740 | lua_pop( L, 1); // ... |
1741 | STACK_MID( L, 0); | 1741 | STACK_CHECK( L, 0); |
1742 | STACK_MID( L2, 2); // ... mt u | 1742 | STACK_CHECK( L2, 2); // ... mt u |
1743 | } | 1743 | } |
1744 | // perform the custom cloning part | 1744 | // perform the custom cloning part |
1745 | lua_insert( L2, -2); // ... u mt | 1745 | lua_insert( L2, -2); // ... u mt |
@@ -1759,8 +1759,8 @@ static bool inter_copy_function(Universe* U, lua_State* L2, int L2_cache_i, lua_ | |||
1759 | copy_cached_func( U, L2, L2_cache_i, L, source_i_, mode_, upName_); // ... f | 1759 | copy_cached_func( U, L2, L2_cache_i, L, source_i_, mode_, upName_); // ... f |
1760 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); | 1760 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); |
1761 | } | 1761 | } |
1762 | STACK_END( L2, 1); | 1762 | STACK_CHECK( L2, 1); |
1763 | STACK_END( L, 0); | 1763 | STACK_CHECK( L, 0); |
1764 | return true; | 1764 | return true; |
1765 | } | 1765 | } |
1766 | 1766 | ||
@@ -1771,8 +1771,8 @@ static bool inter_copy_table(Universe* U, lua_State* L2, int L2_cache_i, lua_Sta | |||
1771 | return false; | 1771 | return false; |
1772 | } | 1772 | } |
1773 | 1773 | ||
1774 | STACK_CHECK( L, 0); | 1774 | STACK_CHECK_START_REL(L, 0); |
1775 | STACK_CHECK( L2, 0); | 1775 | STACK_CHECK_START_REL(L2, 0); |
1776 | DEBUGSPEW_CODE( fprintf( stderr, "TABLE %s\n", upName_)); | 1776 | DEBUGSPEW_CODE( fprintf( stderr, "TABLE %s\n", upName_)); |
1777 | 1777 | ||
1778 | /* | 1778 | /* |
@@ -1811,16 +1811,16 @@ static bool inter_copy_table(Universe* U, lua_State* L2, int L2_cache_i, lua_Sta | |||
1811 | inter_copy_keyvaluepair( U, L2, L2_cache_i, L, vt, mode_, upName_); | 1811 | inter_copy_keyvaluepair( U, L2, L2_cache_i, L, vt, mode_, upName_); |
1812 | lua_pop( L, 1); // pop value (next round) | 1812 | lua_pop( L, 1); // pop value (next round) |
1813 | } | 1813 | } |
1814 | STACK_MID( L, 0); | 1814 | STACK_CHECK( L, 0); |
1815 | STACK_MID( L2, 1); | 1815 | STACK_CHECK( L2, 1); |
1816 | 1816 | ||
1817 | // Metatables are expected to be immutable, and copied only once. | 1817 | // Metatables are expected to be immutable, and copied only once. |
1818 | if( push_cached_metatable( U, L2, L2_cache_i, L, i, mode_, upName_)) // ... t mt? | 1818 | if( push_cached_metatable( U, L2, L2_cache_i, L, i, mode_, upName_)) // ... t mt? |
1819 | { | 1819 | { |
1820 | lua_setmetatable( L2, -2); // ... t | 1820 | lua_setmetatable( L2, -2); // ... t |
1821 | } | 1821 | } |
1822 | STACK_END( L2, 1); | 1822 | STACK_CHECK( L2, 1); |
1823 | STACK_END( L, 0); | 1823 | STACK_CHECK( L, 0); |
1824 | return true; | 1824 | return true; |
1825 | } | 1825 | } |
1826 | 1826 | ||
@@ -1840,8 +1840,8 @@ bool inter_copy_one(Universe* U, lua_State* L2, int L2_cache_i, lua_State* L, in | |||
1840 | int val_type = lua_type( L, i); | 1840 | int val_type = lua_type( L, i); |
1841 | static int const pod_mask = (1 << LUA_TNIL) | (1 << LUA_TBOOLEAN) | (1 << LUA_TLIGHTUSERDATA) | (1 << LUA_TNUMBER) | (1 << LUA_TSTRING); | 1841 | static int const pod_mask = (1 << LUA_TNIL) | (1 << LUA_TBOOLEAN) | (1 << LUA_TLIGHTUSERDATA) | (1 << LUA_TNUMBER) | (1 << LUA_TSTRING); |
1842 | STACK_GROW( L2, 1); | 1842 | STACK_GROW( L2, 1); |
1843 | STACK_CHECK( L, 0); // L // L2 | 1843 | STACK_CHECK_START_REL(L, 0); // L // L2 |
1844 | STACK_CHECK( L2, 0); // L // L2 | 1844 | STACK_CHECK_START_REL(L2, 0); // L // L2 |
1845 | 1845 | ||
1846 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "inter_copy_one()\n" INDENT_END)); | 1846 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "inter_copy_one()\n" INDENT_END)); |
1847 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); | 1847 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); |
@@ -1861,7 +1861,7 @@ bool inter_copy_one(Universe* U, lua_State* L2, int L2_cache_i, lua_State* L, in | |||
1861 | lua_pop( L, 2); // ... | 1861 | lua_pop( L, 2); // ... |
1862 | } | 1862 | } |
1863 | } | 1863 | } |
1864 | STACK_MID( L, 0); | 1864 | STACK_CHECK( L, 0); |
1865 | 1865 | ||
1866 | /* Lets push nil to L2 if the object should be ignored */ | 1866 | /* Lets push nil to L2 if the object should be ignored */ |
1867 | switch( val_type) | 1867 | switch( val_type) |
@@ -1945,8 +1945,8 @@ bool inter_copy_one(Universe* U, lua_State* L2, int L2_cache_i, lua_State* L, in | |||
1945 | 1945 | ||
1946 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); | 1946 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); |
1947 | 1947 | ||
1948 | STACK_END( L2, ret ? 1 : 0); | 1948 | STACK_CHECK( L2, ret ? 1 : 0); |
1949 | STACK_END( L, 0); | 1949 | STACK_CHECK( L, 0); |
1950 | return ret; | 1950 | return ret; |
1951 | } | 1951 | } |
1952 | 1952 | ||
@@ -1977,7 +1977,7 @@ int luaG_inter_copy(Universe* U, lua_State* L, lua_State* L2, int n, LookupMode | |||
1977 | return -1; | 1977 | return -1; |
1978 | } | 1978 | } |
1979 | 1979 | ||
1980 | STACK_CHECK( L2, 0); | 1980 | STACK_CHECK_START_REL(L2, 0); |
1981 | STACK_GROW( L2, n + 1); | 1981 | STACK_GROW( L2, n + 1); |
1982 | 1982 | ||
1983 | /* | 1983 | /* |
@@ -1987,7 +1987,7 @@ int luaG_inter_copy(Universe* U, lua_State* L, lua_State* L2, int n, LookupMode | |||
1987 | */ | 1987 | */ |
1988 | lua_newtable( L2); // ... cache | 1988 | lua_newtable( L2); // ... cache |
1989 | 1989 | ||
1990 | STACK_CHECK( L, 0); | 1990 | STACK_CHECK_START_REL(L, 0); |
1991 | for( i = top_L - n + 1, j = 1; i <= top_L; ++ i, ++ j) | 1991 | for( i = top_L - n + 1, j = 1; i <= top_L; ++ i, ++ j) |
1992 | { | 1992 | { |
1993 | if( U->verboseErrors) | 1993 | if( U->verboseErrors) |
@@ -2000,13 +2000,13 @@ int luaG_inter_copy(Universe* U, lua_State* L, lua_State* L2, int n, LookupMode | |||
2000 | break; | 2000 | break; |
2001 | } | 2001 | } |
2002 | } | 2002 | } |
2003 | STACK_END( L, 0); | 2003 | STACK_CHECK( L, 0); |
2004 | 2004 | ||
2005 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); | 2005 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); |
2006 | 2006 | ||
2007 | if( copyok) | 2007 | if( copyok) |
2008 | { | 2008 | { |
2009 | STACK_MID( L2, n + 1); | 2009 | STACK_CHECK( L2, n + 1); |
2010 | // Remove the cache table. Persistent caching would cause i.e. multiple | 2010 | // Remove the cache table. Persistent caching would cause i.e. multiple |
2011 | // messages passed in the same table to use the same table also in receiving end. | 2011 | // messages passed in the same table to use the same table also in receiving end. |
2012 | lua_remove( L2, top_L2 + 1); | 2012 | lua_remove( L2, top_L2 + 1); |
@@ -2015,7 +2015,7 @@ int luaG_inter_copy(Universe* U, lua_State* L, lua_State* L2, int n, LookupMode | |||
2015 | 2015 | ||
2016 | // error -> pop everything from the target state stack | 2016 | // error -> pop everything from the target state stack |
2017 | lua_settop( L2, top_L2); | 2017 | lua_settop( L2, top_L2); |
2018 | STACK_END( L2, 0); | 2018 | STACK_CHECK( L2, 0); |
2019 | return -2; | 2019 | return -2; |
2020 | } | 2020 | } |
2021 | 2021 | ||
@@ -2032,13 +2032,13 @@ int luaG_inter_copy_package( Universe* U, lua_State* L, lua_State* L2, int packa | |||
2032 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "luaG_inter_copy_package()\n" INDENT_END)); | 2032 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "luaG_inter_copy_package()\n" INDENT_END)); |
2033 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); | 2033 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); |
2034 | // package | 2034 | // package |
2035 | STACK_CHECK( L, 0); | 2035 | STACK_CHECK_START_REL(L, 0); |
2036 | STACK_CHECK( L2, 0); | 2036 | STACK_CHECK_START_REL(L2, 0); |
2037 | package_idx_ = lua_absindex( L, package_idx_); | 2037 | package_idx_ = lua_absindex( L, package_idx_); |
2038 | if( lua_type( L, package_idx_) != LUA_TTABLE) | 2038 | if( lua_type( L, package_idx_) != LUA_TTABLE) |
2039 | { | 2039 | { |
2040 | lua_pushfstring( L, "expected package as table, got %s", luaL_typename( L, package_idx_)); | 2040 | lua_pushfstring( L, "expected package as table, got %s", luaL_typename( L, package_idx_)); |
2041 | STACK_MID( L, 1); | 2041 | STACK_CHECK( L, 1); |
2042 | // raise the error when copying from lane to lane, else just leave it on the stack to be raised later | 2042 | // raise the error when copying from lane to lane, else just leave it on the stack to be raised later |
2043 | return ( mode_ == eLM_LaneBody) ? lua_error( L) : 1; | 2043 | return ( mode_ == eLM_LaneBody) ? lua_error( L) : 1; |
2044 | } | 2044 | } |
@@ -2073,8 +2073,8 @@ int luaG_inter_copy_package( Universe* U, lua_State* L, lua_State* L2, int packa | |||
2073 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "'package' not loaded, nothing to do\n" INDENT_END)); | 2073 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "'package' not loaded, nothing to do\n" INDENT_END)); |
2074 | } | 2074 | } |
2075 | lua_pop( L2, 1); | 2075 | lua_pop( L2, 1); |
2076 | STACK_END( L2, 0); | 2076 | STACK_CHECK( L2, 0); |
2077 | STACK_END( L, 0); | 2077 | STACK_CHECK( L, 0); |
2078 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); | 2078 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); |
2079 | return 0; | 2079 | return 0; |
2080 | } | 2080 | } |