diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lanes.c | 5 | ||||
| -rw-r--r-- | src/tools.c | 122 |
2 files changed, 92 insertions, 35 deletions
diff --git a/src/lanes.c b/src/lanes.c index ae29af2..f32cf6e 100644 --- a/src/lanes.c +++ b/src/lanes.c | |||
| @@ -2162,7 +2162,7 @@ LUAG_FUNC( configure) | |||
| 2162 | 2162 | ||
| 2163 | // Proxy userdata contents is only a 'DEEP_PRELUDE*' pointer | 2163 | // Proxy userdata contents is only a 'DEEP_PRELUDE*' pointer |
| 2164 | U->timer_deep = *(DeepPrelude**) lua_touserdata( L, -1); | 2164 | U->timer_deep = *(DeepPrelude**) lua_touserdata( L, -1); |
| 2165 | // increment refcount that this linda remains alive as long as the universe is. | 2165 | // increment refcount so that this linda remains alive as long as the universe exists. |
| 2166 | ++ U->timer_deep->refcount; | 2166 | ++ U->timer_deep->refcount; |
| 2167 | lua_pop( L, 1); // settings | 2167 | lua_pop( L, 1); // settings |
| 2168 | } | 2168 | } |
| @@ -2190,7 +2190,7 @@ LUAG_FUNC( configure) | |||
| 2190 | 2190 | ||
| 2191 | { | 2191 | { |
| 2192 | char const* errmsg; | 2192 | char const* errmsg; |
| 2193 | errmsg = push_deep_proxy( U, L, (DeepPrelude*) U->timer_deep, eLM_LaneBody);// settings M timer_deep | 2193 | errmsg = push_deep_proxy( U, L, (DeepPrelude*) U->timer_deep, eLM_LaneBody); // settings M timer_deep |
| 2194 | if( errmsg != NULL) | 2194 | if( errmsg != NULL) |
| 2195 | { | 2195 | { |
| 2196 | return luaL_error( L, errmsg); | 2196 | return luaL_error( L, errmsg); |
| @@ -2250,6 +2250,7 @@ LUAG_FUNC( configure) | |||
| 2250 | // we process it before _G because we don't want to find the module when scanning _G (this would generate longer names) | 2250 | // we process it before _G because we don't want to find the module when scanning _G (this would generate longer names) |
| 2251 | // for example in package.loaded["lanes.core"].* | 2251 | // for example in package.loaded["lanes.core"].* |
| 2252 | populate_func_lookup_table( L, -1, name); | 2252 | populate_func_lookup_table( L, -1, name); |
| 2253 | STACK_MID( L, 2); | ||
| 2253 | 2254 | ||
| 2254 | // record all existing C/JIT-fast functions | 2255 | // record all existing C/JIT-fast functions |
| 2255 | // Lua 5.2 no longer has LUA_GLOBALSINDEX: we must push globals table on the stack | 2256 | // Lua 5.2 no longer has LUA_GLOBALSINDEX: we must push globals table on the stack |
diff --git a/src/tools.c b/src/tools.c index e54e0c0..d358e96 100644 --- a/src/tools.c +++ b/src/tools.c | |||
| @@ -144,6 +144,10 @@ static void copy_one_time_settings( Universe* U, lua_State* L, lua_State* L2) | |||
| 144 | STACK_GROW( L, 2); | 144 | STACK_GROW( L, 2); |
| 145 | STACK_CHECK( L, 0); | 145 | STACK_CHECK( L, 0); |
| 146 | STACK_CHECK( L2, 0); | 146 | STACK_CHECK( L2, 0); |
| 147 | |||
| 148 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "copy_one_time_settings()\n" INDENT_END)); | ||
| 149 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); | ||
| 150 | |||
| 147 | REGISTRY_GET( L, CONFIG_REGKEY); // config | 151 | REGISTRY_GET( L, CONFIG_REGKEY); // config |
| 148 | // copy settings from from source to destination registry | 152 | // copy settings from from source to destination registry |
| 149 | if( luaG_inter_move( U, L, L2, 1, eLM_LaneBody) < 0) // // config | 153 | if( luaG_inter_move( U, L, L2, 1, eLM_LaneBody) < 0) // // config |
| @@ -154,6 +158,7 @@ static void copy_one_time_settings( Universe* U, lua_State* L, lua_State* L2) | |||
| 154 | REGISTRY_SET( L2, CONFIG_REGKEY, lua_insert( L2, -2)); // | 158 | REGISTRY_SET( L2, CONFIG_REGKEY, lua_insert( L2, -2)); // |
| 155 | STACK_END( L2, 0); | 159 | STACK_END( L2, 0); |
| 156 | STACK_END( L, 0); | 160 | STACK_END( L, 0); |
| 161 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); | ||
| 157 | } | 162 | } |
| 158 | 163 | ||
| 159 | 164 | ||
| @@ -331,7 +336,7 @@ static char const* luaG_pushFQN( lua_State* L, int t, int last, size_t* length) | |||
| 331 | * if we already had an entry of type [o] = ..., replace the name if the new one is shorter | 336 | * if we already had an entry of type [o] = ..., replace the name if the new one is shorter |
| 332 | * pops the processed object from the stack | 337 | * pops the processed object from the stack |
| 333 | */ | 338 | */ |
| 334 | static void update_lookup_entry( lua_State* L, int _ctx_base, int _depth) | 339 | static void update_lookup_entry( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* L, int _ctx_base, int _depth) |
| 335 | { | 340 | { |
| 336 | // slot 1 in the stack contains the table that receives everything we found | 341 | // slot 1 in the stack contains the table that receives everything we found |
| 337 | int const dest = _ctx_base; | 342 | int const dest = _ctx_base; |
| @@ -341,7 +346,8 @@ static void update_lookup_entry( lua_State* L, int _ctx_base, int _depth) | |||
| 341 | size_t prevNameLength, newNameLength; | 346 | size_t prevNameLength, newNameLength; |
| 342 | char const* prevName; | 347 | char const* prevName; |
| 343 | DEBUGSPEW_CODE( char const *newName); | 348 | DEBUGSPEW_CODE( char const *newName); |
| 344 | DEBUGSPEW_CODE( Universe* U = universe_get( L)); | 349 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "update_lookup_entry()\n" INDENT_END)); |
| 350 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); | ||
| 345 | 351 | ||
| 346 | STACK_CHECK( L, 0); | 352 | STACK_CHECK( L, 0); |
| 347 | // first, raise an error if the function is already known | 353 | // first, raise an error if the function is already known |
| @@ -401,9 +407,10 @@ static void update_lookup_entry( lua_State* L, int _ctx_base, int _depth) | |||
| 401 | } | 407 | } |
| 402 | -- _depth; | 408 | -- _depth; |
| 403 | STACK_END( L, -1); | 409 | STACK_END( L, -1); |
| 410 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); | ||
| 404 | } | 411 | } |
| 405 | 412 | ||
| 406 | static void populate_func_lookup_table_recur( lua_State* L, int _ctx_base, int _i, int _depth) | 413 | static void populate_func_lookup_table_recur( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* L, int _ctx_base, int _i, int _depth) |
| 407 | { | 414 | { |
| 408 | lua_Integer visit_count; | 415 | lua_Integer visit_count; |
| 409 | // slot 2 contains a table that, when concatenated, produces the fully qualified name of scanned elements in the table provided at slot _i | 416 | // slot 2 contains a table that, when concatenated, produces the fully qualified name of scanned elements in the table provided at slot _i |
| @@ -412,7 +419,8 @@ static void populate_func_lookup_table_recur( lua_State* L, int _ctx_base, int _ | |||
| 412 | int const cache = _ctx_base + 2; | 419 | int const cache = _ctx_base + 2; |
| 413 | // we need to remember subtables to process them after functions encountered at the current depth (breadth-first search) | 420 | // we need to remember subtables to process them after functions encountered at the current depth (breadth-first search) |
| 414 | int const breadth_first_cache = lua_gettop( L) + 1; | 421 | int const breadth_first_cache = lua_gettop( L) + 1; |
| 415 | DEBUGSPEW_CODE( Universe* U = universe_get( L)); | 422 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "populate_func_lookup_table_recur()\n" INDENT_END)); |
| 423 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); | ||
| 416 | 424 | ||
| 417 | STACK_GROW( L, 6); | 425 | STACK_GROW( L, 6); |
| 418 | // slot _i contains a table where we search for functions (or a full userdata with a metatable) | 426 | // slot _i contains a table where we search for functions (or a full userdata with a metatable) |
| @@ -433,6 +441,8 @@ static void populate_func_lookup_table_recur( lua_State* L, int _ctx_base, int _ | |||
| 433 | STACK_MID( L, 0); | 441 | STACK_MID( L, 0); |
| 434 | if( visit_count > 0) | 442 | if( visit_count > 0) |
| 435 | { | 443 | { |
| 444 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "already visited\n" INDENT_END)); | ||
| 445 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); | ||
| 436 | return; | 446 | return; |
| 437 | } | 447 | } |
| 438 | 448 | ||
| @@ -467,12 +477,12 @@ static void populate_func_lookup_table_recur( lua_State* L, int _ctx_base, int _ | |||
| 467 | lua_pushvalue( L, -2); // ... {_i} {bfc} k {} k {} | 477 | lua_pushvalue( L, -2); // ... {_i} {bfc} k {} k {} |
| 468 | lua_rawset( L, breadth_first_cache); // ... {_i} {bfc} k {} | 478 | lua_rawset( L, breadth_first_cache); // ... {_i} {bfc} k {} |
| 469 | // generate a name, and if we already had one name, keep whichever is the shorter | 479 | // generate a name, and if we already had one name, keep whichever is the shorter |
| 470 | update_lookup_entry( L, _ctx_base, _depth); // ... {_i} {bfc} k | 480 | update_lookup_entry( DEBUGSPEW_PARAM_COMMA( U) L, _ctx_base, _depth); // ... {_i} {bfc} k |
| 471 | } | 481 | } |
| 472 | else if( lua_isfunction( L, -1) && (luaG_getfuncsubtype( L, -1) != FST_Bytecode)) // ... {_i} {bfc} k func | 482 | else if( lua_isfunction( L, -1) && (luaG_getfuncsubtype( L, -1) != FST_Bytecode)) // ... {_i} {bfc} k func |
| 473 | { | 483 | { |
| 474 | // generate a name, and if we already had one name, keep whichever is the shorter | 484 | // generate a name, and if we already had one name, keep whichever is the shorter |
| 475 | update_lookup_entry( L, _ctx_base, _depth); // ... {_i} {bfc} k | 485 | update_lookup_entry( DEBUGSPEW_PARAM_COMMA( U) L, _ctx_base, _depth); // ... {_i} {bfc} k |
| 476 | } | 486 | } |
| 477 | else | 487 | else |
| 478 | { | 488 | { |
| @@ -507,7 +517,7 @@ static void populate_func_lookup_table_recur( lua_State* L, int _ctx_base, int _ | |||
| 507 | // push table name in fqn stack (note that concatenation will crash if name is a not string!) | 517 | // push table name in fqn stack (note that concatenation will crash if name is a not string!) |
| 508 | lua_pushvalue( L, -2); // ... {_i} {bfc} k {} k | 518 | lua_pushvalue( L, -2); // ... {_i} {bfc} k {} k |
| 509 | lua_rawseti( L, fqn, _depth); // ... {_i} {bfc} k {} | 519 | lua_rawseti( L, fqn, _depth); // ... {_i} {bfc} k {} |
| 510 | populate_func_lookup_table_recur( L, _ctx_base, lua_gettop( L), _depth); // ... {_i} {bfc} k {} | 520 | populate_func_lookup_table_recur( DEBUGSPEW_PARAM_COMMA( U) L, _ctx_base, lua_gettop( L), _depth); |
| 511 | lua_pop( L, 1); // ... {_i} {bfc} k | 521 | lua_pop( L, 1); // ... {_i} {bfc} k |
| 512 | STACK_MID( L, 2); | 522 | STACK_MID( L, 2); |
| 513 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); | 523 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); |
| @@ -520,6 +530,7 @@ static void populate_func_lookup_table_recur( lua_State* L, int _ctx_base, int _ | |||
| 520 | lua_pop( L, 1); // ... {_i} | 530 | lua_pop( L, 1); // ... {_i} |
| 521 | STACK_END( L, 0); | 531 | STACK_END( L, 0); |
| 522 | // we are done // ... {_i} {bfc} | 532 | // we are done // ... {_i} {bfc} |
| 533 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); | ||
| 523 | } | 534 | } |
| 524 | 535 | ||
| 525 | /* | 536 | /* |
| @@ -535,46 +546,46 @@ void populate_func_lookup_table( lua_State* L, int _i, char const* name_) | |||
| 535 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); | 546 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); |
| 536 | STACK_GROW( L, 3); | 547 | STACK_GROW( L, 3); |
| 537 | STACK_CHECK( L, 0); | 548 | STACK_CHECK( L, 0); |
| 538 | REGISTRY_GET( L, LOOKUP_REGKEY); // {} | 549 | REGISTRY_GET( L, LOOKUP_REGKEY); // {} |
| 539 | STACK_MID( L, 1); | 550 | STACK_MID( L, 1); |
| 540 | ASSERT_L( lua_istable( L, -1)); | 551 | ASSERT_L( lua_istable( L, -1)); |
| 541 | if( lua_type( L, in_base) == LUA_TFUNCTION) // for example when a module is a simple function | 552 | if( lua_type( L, in_base) == LUA_TFUNCTION) // for example when a module is a simple function |
| 542 | { | 553 | { |
| 543 | name_ = name_ ? name_ : "NULL"; | 554 | name_ = name_ ? name_ : "NULL"; |
| 544 | lua_pushvalue( L, in_base); // {} f | 555 | lua_pushvalue( L, in_base); // {} f |
| 545 | lua_pushstring( L, name_); // {} f _name | 556 | lua_pushstring( L, name_); // {} f _name |
| 546 | lua_rawset( L, -3); // {} | 557 | lua_rawset( L, -3); // {} |
| 547 | lua_pushstring( L, name_); // {} _name | 558 | lua_pushstring( L, name_); // {} _name |
| 548 | lua_pushvalue( L, in_base); // {} _name f | 559 | lua_pushvalue( L, in_base); // {} _name f |
| 549 | lua_rawset( L, -3); // {} | 560 | lua_rawset( L, -3); // {} |
| 550 | lua_pop( L, 1); // | 561 | lua_pop( L, 1); // |
| 551 | } | 562 | } |
| 552 | else if( lua_type( L, in_base) == LUA_TTABLE) | 563 | else if( lua_type( L, in_base) == LUA_TTABLE) |
| 553 | { | 564 | { |
| 554 | lua_newtable( L); // {} {fqn} | 565 | lua_newtable( L); // {} {fqn} |
| 555 | if( name_) | 566 | if( name_) |
| 556 | { | 567 | { |
| 557 | STACK_MID( L, 2); | 568 | STACK_MID( L, 2); |
| 558 | lua_pushstring( L, name_); // {} {fqn} "name" | 569 | lua_pushstring( L, name_); // {} {fqn} "name" |
| 559 | // generate a name, and if we already had one name, keep whichever is the shorter | 570 | // generate a name, and if we already had one name, keep whichever is the shorter |
| 560 | lua_pushvalue( L, in_base); // {} {fqn} "name" t | 571 | lua_pushvalue( L, in_base); // {} {fqn} "name" t |
| 561 | update_lookup_entry( L, ctx_base, start_depth); // {} {fqn} "name" | 572 | update_lookup_entry( DEBUGSPEW_PARAM_COMMA( U) L, ctx_base, start_depth); // {} {fqn} "name" |
| 562 | // don't forget to store the name at the bottom of the fqn stack | 573 | // don't forget to store the name at the bottom of the fqn stack |
| 563 | ++ start_depth; | 574 | ++ start_depth; |
| 564 | lua_rawseti( L, -2, start_depth); // {} {fqn} | 575 | lua_rawseti( L, -2, start_depth); // {} {fqn} |
| 565 | STACK_MID( L, 2); | 576 | STACK_MID( L, 2); |
| 566 | } | 577 | } |
| 567 | // retrieve the cache, create it if we haven't done it yet | 578 | // retrieve the cache, create it if we haven't done it yet |
| 568 | lua_getfield( L, LUA_REGISTRYINDEX, LOOKUP_KEY_CACHE); // {} {fqn} {cache}? | 579 | lua_getfield( L, LUA_REGISTRYINDEX, LOOKUP_KEY_CACHE); // {} {fqn} {cache}? |
| 569 | if( lua_isnil( L, -1)) | 580 | if( lua_isnil( L, -1)) |
| 570 | { | 581 | { |
| 571 | lua_pop( L, 1); // {} {fqn} | 582 | lua_pop( L, 1); // {} {fqn} |
| 572 | lua_newtable( L); // {} {fqn} {cache} | 583 | lua_newtable( L); // {} {fqn} {cache} |
| 573 | lua_pushvalue( L, -1); // {} {fqn} {cache} {cache} | 584 | lua_pushvalue( L, -1); // {} {fqn} {cache} {cache} |
| 574 | lua_setfield( L, LUA_REGISTRYINDEX, LOOKUP_KEY_CACHE); // {} {fqn} {cache} | 585 | lua_setfield( L, LUA_REGISTRYINDEX, LOOKUP_KEY_CACHE); // {} {fqn} {cache} |
| 575 | } | 586 | } |
| 576 | // process everything we find in that table, filling in lookup data for all functions and tables we see there | 587 | // process everything we find in that table, filling in lookup data for all functions and tables we see there |
| 577 | populate_func_lookup_table_recur( L, ctx_base, in_base, start_depth); // {...} {fqn} {cache} | 588 | populate_func_lookup_table_recur( DEBUGSPEW_PARAM_COMMA( U) L, ctx_base, in_base, start_depth); |
| 578 | lua_pop( L, 3); | 589 | lua_pop( L, 3); |
| 579 | } | 590 | } |
| 580 | else | 591 | else |
| @@ -1294,6 +1305,29 @@ enum e_vt | |||
| 1294 | }; | 1305 | }; |
| 1295 | static bool_t inter_copy_one_( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum e_vt value_type, LookupMode mode_, char const* upName_); | 1306 | static bool_t inter_copy_one_( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum e_vt value_type, LookupMode mode_, char const* upName_); |
| 1296 | 1307 | ||
| 1308 | #if USE_DEBUG_SPEW | ||
| 1309 | static char const* lua_type_names[] = | ||
| 1310 | { | ||
| 1311 | "LUA_TNIL" | ||
| 1312 | , "LUA_TBOOLEAN" | ||
| 1313 | , "LUA_TLIGHTUSERDATA" | ||
| 1314 | , "LUA_TNUMBER" | ||
| 1315 | , "LUA_TSTRING" | ||
| 1316 | , "LUA_TTABLE" | ||
| 1317 | , "LUA_TFUNCTION" | ||
| 1318 | , "LUA_TUSERDATA" | ||
| 1319 | , "LUA_TTHREAD" | ||
| 1320 | , "<LUA_NUMTAGS>" // not really a type | ||
| 1321 | , "LUA_TJITCDATA" // LuaJIT specific | ||
| 1322 | }; | ||
| 1323 | static char const* vt_names[] = | ||
| 1324 | { | ||
| 1325 | "VT_NORMAL" | ||
| 1326 | , "VT_KEY" | ||
| 1327 | , "VT_METATABLE" | ||
| 1328 | }; | ||
| 1329 | #endif // USE_DEBUG_SPEW | ||
| 1330 | |||
| 1297 | static void inter_copy_func( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, LookupMode mode_, char const* upName_) | 1331 | static void inter_copy_func( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, LookupMode mode_, char const* upName_) |
| 1298 | { | 1332 | { |
| 1299 | int n, needToPush; | 1333 | int n, needToPush; |
| @@ -1618,12 +1652,17 @@ static bool_t inter_copy_one_( Universe* U, lua_State* L2, uint_t L2_cache_i, lu | |||
| 1618 | STACK_CHECK( L, 0); // L // L2 | 1652 | STACK_CHECK( L, 0); // L // L2 |
| 1619 | STACK_CHECK( L2, 0); // L // L2 | 1653 | STACK_CHECK( L2, 0); // L // L2 |
| 1620 | 1654 | ||
| 1655 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "inter_copy_one_()\n" INDENT_END)); | ||
| 1656 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); | ||
| 1657 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%s %s: " INDENT_END, lua_type_names[val_type], vt_names[vt])); | ||
| 1658 | |||
| 1621 | /* Skip the object if it has metatable with { __lanesignore = true } */ | 1659 | /* Skip the object if it has metatable with { __lanesignore = true } */ |
| 1622 | if( lua_getmetatable( L, i)) // ... mt | 1660 | if( lua_getmetatable( L, i)) // ... mt |
| 1623 | { | 1661 | { |
| 1624 | lua_getfield( L, -1, "__lanesignore"); // ... mt ignore? | 1662 | lua_getfield( L, -1, "__lanesignore"); // ... mt ignore? |
| 1625 | if( lua_isboolean( L, -1) && lua_toboolean( L, -1)) | 1663 | if( lua_isboolean( L, -1) && lua_toboolean( L, -1)) |
| 1626 | { | 1664 | { |
| 1665 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "__lanesignore -> LUA_TNIL\n" INDENT_END)); | ||
| 1627 | val_type = LUA_TNIL; | 1666 | val_type = LUA_TNIL; |
| 1628 | } | 1667 | } |
| 1629 | lua_pop( L, 2); // ... | 1668 | lua_pop( L, 2); // ... |
| @@ -1636,7 +1675,11 @@ static bool_t inter_copy_one_( Universe* U, lua_State* L2, uint_t L2_cache_i, lu | |||
| 1636 | /* Basic types allowed both as values, and as table keys */ | 1675 | /* Basic types allowed both as values, and as table keys */ |
| 1637 | 1676 | ||
| 1638 | case LUA_TBOOLEAN: | 1677 | case LUA_TBOOLEAN: |
| 1639 | lua_pushboolean( L2, lua_toboolean( L, i)); | 1678 | { |
| 1679 | bool_t v = lua_toboolean( L, i); | ||
| 1680 | DEBUGSPEW_CODE( fprintf( stderr, "%s\n", v ? "true" : "false")); | ||
| 1681 | lua_pushboolean( L2, v); | ||
| 1682 | } | ||
| 1640 | break; | 1683 | break; |
| 1641 | 1684 | ||
| 1642 | case LUA_TNUMBER: | 1685 | case LUA_TNUMBER: |
| @@ -1645,7 +1688,7 @@ static bool_t inter_copy_one_( Universe* U, lua_State* L2, uint_t L2_cache_i, lu | |||
| 1645 | if( lua_isinteger( L, i)) | 1688 | if( lua_isinteger( L, i)) |
| 1646 | { | 1689 | { |
| 1647 | lua_Integer v = lua_tointeger( L, i); | 1690 | lua_Integer v = lua_tointeger( L, i); |
| 1648 | DEBUGSPEW_CODE( if( vt == VT_KEY) fprintf( stderr, INDENT_BEGIN "KEY: " LUA_INTEGER_FMT "\n" INDENT_END, v)); | 1691 | DEBUGSPEW_CODE( fprintf( stderr, LUA_INTEGER_FMT "\n", v)); |
| 1649 | lua_pushinteger( L2, v); | 1692 | lua_pushinteger( L2, v); |
| 1650 | break; | 1693 | break; |
| 1651 | } | 1694 | } |
| @@ -1653,7 +1696,7 @@ static bool_t inter_copy_one_( Universe* U, lua_State* L2, uint_t L2_cache_i, lu | |||
| 1653 | #endif // defined LUA_LNUM || LUA_VERSION_NUM >= 503 | 1696 | #endif // defined LUA_LNUM || LUA_VERSION_NUM >= 503 |
| 1654 | { | 1697 | { |
| 1655 | lua_Number v = lua_tonumber( L, i); | 1698 | lua_Number v = lua_tonumber( L, i); |
| 1656 | DEBUGSPEW_CODE( if( vt == VT_KEY) fprintf( stderr, INDENT_BEGIN "KEY: " LUA_NUMBER_FMT "\n" INDENT_END, v)); | 1699 | DEBUGSPEW_CODE( fprintf( stderr, LUA_NUMBER_FMT "\n", v)); |
| 1657 | lua_pushnumber( L2, v); | 1700 | lua_pushnumber( L2, v); |
| 1658 | } | 1701 | } |
| 1659 | break; | 1702 | break; |
| @@ -1662,13 +1705,17 @@ static bool_t inter_copy_one_( Universe* U, lua_State* L2, uint_t L2_cache_i, lu | |||
| 1662 | { | 1705 | { |
| 1663 | size_t len; | 1706 | size_t len; |
| 1664 | char const* s = lua_tolstring( L, i, &len); | 1707 | char const* s = lua_tolstring( L, i, &len); |
| 1665 | DEBUGSPEW_CODE( if( vt == VT_KEY) fprintf( stderr, INDENT_BEGIN "KEY: '%s'\n" INDENT_END, s)); | 1708 | DEBUGSPEW_CODE( fprintf( stderr, "'%s'\n", s)); |
| 1666 | lua_pushlstring( L2, s, len); | 1709 | lua_pushlstring( L2, s, len); |
| 1667 | } | 1710 | } |
| 1668 | break; | 1711 | break; |
| 1669 | 1712 | ||
| 1670 | case LUA_TLIGHTUSERDATA: | 1713 | case LUA_TLIGHTUSERDATA: |
| 1671 | lua_pushlightuserdata( L2, lua_touserdata( L, i)); | 1714 | { |
| 1715 | void* p = lua_touserdata( L, i); | ||
| 1716 | DEBUGSPEW_CODE( fprintf( stderr, "%p\n", p)); | ||
| 1717 | lua_pushlightuserdata( L2, p); | ||
| 1718 | } | ||
| 1672 | break; | 1719 | break; |
| 1673 | 1720 | ||
| 1674 | /* The following types are not allowed as table keys */ | 1721 | /* The following types are not allowed as table keys */ |
| @@ -1680,7 +1727,7 @@ static bool_t inter_copy_one_( Universe* U, lua_State* L2, uint_t L2_cache_i, lu | |||
| 1680 | break; | 1727 | break; |
| 1681 | } | 1728 | } |
| 1682 | // Allow only deep userdata entities to be copied across | 1729 | // Allow only deep userdata entities to be copied across |
| 1683 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "USERDATA\n" INDENT_END)); | 1730 | DEBUGSPEW_CODE( fprintf( stderr, "USERDATA\n")); |
| 1684 | if( copydeep( U, L, L2, i, mode_)) | 1731 | if( copydeep( U, L, L2, i, mode_)) |
| 1685 | { | 1732 | { |
| 1686 | break; | 1733 | break; |
| @@ -1795,7 +1842,7 @@ static bool_t inter_copy_one_( Universe* U, lua_State* L2, uint_t L2_cache_i, lu | |||
| 1795 | } | 1842 | } |
| 1796 | else | 1843 | else |
| 1797 | { | 1844 | { |
| 1798 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "FUNCTION %s\n" INDENT_END, upName_)); | 1845 | DEBUGSPEW_CODE( fprintf( stderr, "FUNCTION %s\n", upName_)); |
| 1799 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); | 1846 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); |
| 1800 | STACK_CHECK( L2, 0); | 1847 | STACK_CHECK( L2, 0); |
| 1801 | push_cached_func( U, L2, L2_cache_i, L, i, mode_, upName_); | 1848 | push_cached_func( U, L2, L2_cache_i, L, i, mode_, upName_); |
| @@ -1813,6 +1860,7 @@ static bool_t inter_copy_one_( Universe* U, lua_State* L2, uint_t L2_cache_i, lu | |||
| 1813 | { | 1860 | { |
| 1814 | STACK_CHECK( L, 0); | 1861 | STACK_CHECK( L, 0); |
| 1815 | STACK_CHECK( L2, 0); | 1862 | STACK_CHECK( L2, 0); |
| 1863 | DEBUGSPEW_CODE( fprintf( stderr, "TABLE %s\n", upName_)); | ||
| 1816 | 1864 | ||
| 1817 | /* | 1865 | /* |
| 1818 | * First, let's try to see if this table is special (aka is it some table that we registered in our lookup databases during module registration?) | 1866 | * First, let's try to see if this table is special (aka is it some table that we registered in our lookup databases during module registration?) |
| @@ -1871,6 +1919,8 @@ static bool_t inter_copy_one_( Universe* U, lua_State* L2, uint_t L2_cache_i, lu | |||
| 1871 | break; | 1919 | break; |
| 1872 | } | 1920 | } |
| 1873 | 1921 | ||
| 1922 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); | ||
| 1923 | |||
| 1874 | STACK_END( L2, ret ? 1 : 0); | 1924 | STACK_END( L2, ret ? 1 : 0); |
| 1875 | STACK_END( L, 0); | 1925 | STACK_END( L, 0); |
| 1876 | return ret; | 1926 | return ret; |
| @@ -1893,9 +1943,13 @@ int luaG_inter_copy( Universe* U, lua_State* L, lua_State* L2, uint_t n, LookupM | |||
| 1893 | char const* pBuf = U->verboseErrors ? tmpBuf : "?"; | 1943 | char const* pBuf = U->verboseErrors ? tmpBuf : "?"; |
| 1894 | bool_t copyok = TRUE; | 1944 | bool_t copyok = TRUE; |
| 1895 | 1945 | ||
| 1946 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "luaG_inter_copy()\n" INDENT_END)); | ||
| 1947 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); | ||
| 1948 | |||
| 1896 | if( n > top_L) | 1949 | if( n > top_L) |
| 1897 | { | 1950 | { |
| 1898 | // requesting to copy more than is available? | 1951 | // requesting to copy more than is available? |
| 1952 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "nothing to copy()\n" INDENT_END)); | ||
| 1899 | return -1; | 1953 | return -1; |
| 1900 | } | 1954 | } |
| 1901 | 1955 | ||
| @@ -1921,6 +1975,8 @@ int luaG_inter_copy( Universe* U, lua_State* L, lua_State* L2, uint_t n, LookupM | |||
| 1921 | } | 1975 | } |
| 1922 | } | 1976 | } |
| 1923 | 1977 | ||
| 1978 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); | ||
| 1979 | |||
| 1924 | /* | 1980 | /* |
| 1925 | * Remove the cache table. Persistent caching would cause i.e. multiple | 1981 | * Remove the cache table. Persistent caching would cause i.e. multiple |
| 1926 | * messages passed in the same table to use the same table also in receiving | 1982 | * messages passed in the same table to use the same table also in receiving |
| @@ -1975,7 +2031,7 @@ int luaG_inter_copy_package( Universe* U, lua_State* L, lua_State* L2, int packa | |||
| 1975 | char const* entries[] = { "path", "cpath", (mode_ == eLM_LaneBody) ? "preload" : NULL/*, (LUA_VERSION_NUM == 501) ? "loaders" : "searchers"*/, NULL}; | 2031 | char const* entries[] = { "path", "cpath", (mode_ == eLM_LaneBody) ? "preload" : NULL/*, (LUA_VERSION_NUM == 501) ? "loaders" : "searchers"*/, NULL}; |
| 1976 | for( i = 0; entries[i]; ++ i) | 2032 | for( i = 0; entries[i]; ++ i) |
| 1977 | { | 2033 | { |
| 1978 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%s\n" INDENT_END, entries[i])); | 2034 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "package.%s\n" INDENT_END, entries[i])); |
| 1979 | lua_getfield( L, package_idx_, entries[i]); | 2035 | lua_getfield( L, package_idx_, entries[i]); |
| 1980 | if( lua_isnil( L, -1)) | 2036 | if( lua_isnil( L, -1)) |
| 1981 | { | 2037 | { |
