aboutsummaryrefslogtreecommitdiff
path: root/src/tools.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools.c')
-rw-r--r--src/tools.c107
1 files changed, 59 insertions, 48 deletions
diff --git a/src/tools.c b/src/tools.c
index 6f71dd8..e54e0c0 100644
--- a/src/tools.c
+++ b/src/tools.c
@@ -32,6 +32,7 @@ THE SOFTWARE.
32*/ 32*/
33 33
34#include <stdio.h> 34#include <stdio.h>
35#include <assert.h>
35#include <string.h> 36#include <string.h>
36#include <ctype.h> 37#include <ctype.h>
37#include <stdlib.h> 38#include <stdlib.h>
@@ -50,14 +51,11 @@ THE SOFTWARE.
50extern bool_t copydeep( Universe* U, lua_State* L, lua_State* L2, int index, LookupMode mode_); 51extern bool_t copydeep( Universe* U, lua_State* L, lua_State* L2, int index, LookupMode mode_);
51extern void push_registry_subtable( lua_State* L, void* key_); 52extern void push_registry_subtable( lua_State* L, void* key_);
52 53
53char const* const CONFIG_REGKEY = "ee932492-a654-4506-9da8-f16540bdb5d4";
54char const* const LOOKUP_REGKEY = "ddea37aa-50c7-4d3f-8e0b-fb7a9d62bac5";
55
56DEBUGSPEW_CODE( char const* debugspew_indent = "----+----!----+----!----+----!----+----!----+----!----+----!----+----!----+"); 54DEBUGSPEW_CODE( char const* debugspew_indent = "----+----!----+----!----+----!----+----!----+----!----+----!----+----!----+");
57 55
58 56
59/*---=== luaG_dump ===---*/ 57/*---=== luaG_dump ===---*/
60 58#ifdef _DEBUG
61void luaG_dump( lua_State* L) 59void luaG_dump( lua_State* L)
62{ 60{
63 int top = lua_gettop( L); 61 int top = lua_gettop( L);
@@ -79,7 +77,7 @@ void luaG_dump( lua_State* L)
79 // Note: this requires 'tostring()' to be defined. If it is NOT, 77 // Note: this requires 'tostring()' to be defined. If it is NOT,
80 // enable it for more debugging. 78 // enable it for more debugging.
81 // 79 //
82 STACK_CHECK( L); 80 STACK_CHECK( L, 0);
83 STACK_GROW( L, 2); 81 STACK_GROW( L, 2);
84 82
85 lua_getglobal( L, "tostring"); 83 lua_getglobal( L, "tostring");
@@ -105,10 +103,11 @@ void luaG_dump( lua_State* L)
105 } 103 }
106 fprintf( stderr, "\n"); 104 fprintf( stderr, "\n");
107} 105}
106#endif // _DEBUG
108 107
109void initialize_on_state_create( Universe* U, lua_State* L) 108void initialize_on_state_create( Universe* U, lua_State* L)
110{ 109{
111 STACK_CHECK( L); 110 STACK_CHECK( L, 0);
112 lua_getfield( L, -1, "on_state_create"); // settings on_state_create|nil 111 lua_getfield( L, -1, "on_state_create"); // settings on_state_create|nil
113 if( !lua_isnil( L, -1)) 112 if( !lua_isnil( L, -1))
114 { 113 {
@@ -142,14 +141,19 @@ void initialize_on_state_create( Universe* U, lua_State* L)
142// just like lua_xmove, args are (from, to) 141// just like lua_xmove, args are (from, to)
143static void copy_one_time_settings( Universe* U, lua_State* L, lua_State* L2) 142static void copy_one_time_settings( Universe* U, lua_State* L, lua_State* L2)
144{ 143{
145 STACK_GROW( L, 1); 144 STACK_GROW( L, 2);
145 STACK_CHECK( L, 0);
146 STACK_CHECK( L2, 0);
147 REGISTRY_GET( L, CONFIG_REGKEY); // config
146 // copy settings from from source to destination registry 148 // copy settings from from source to destination registry
147 lua_getfield( L, LUA_REGISTRYINDEX, CONFIG_REGKEY); 149 if( luaG_inter_move( U, L, L2, 1, eLM_LaneBody) < 0) // // config
148 if( luaG_inter_move( U, L, L2, 1, eLM_LaneBody) < 0) // error?
149 { 150 {
150 (void) luaL_error( L, "failed to copy settings when loading lanes.core"); 151 (void) luaL_error( L, "failed to copy settings when loading lanes.core");
151 } 152 }
152 lua_setfield( L2, LUA_REGISTRYINDEX, CONFIG_REGKEY); 153 // set L2:_R[CONFIG_REGKEY] = settings
154 REGISTRY_SET( L2, CONFIG_REGKEY, lua_insert( L2, -2)); //
155 STACK_END( L2, 0);
156 STACK_END( L, 0);
153} 157}
154 158
155 159
@@ -212,7 +216,7 @@ static void open1lib( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* L, char con
212 { 216 {
213 bool_t const isLanesCore = (libfunc == require_lanes_core) ? TRUE : FALSE; // don't want to create a global for "lanes.core" 217 bool_t const isLanesCore = (libfunc == require_lanes_core) ? TRUE : FALSE; // don't want to create a global for "lanes.core"
214 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "opening %.*s library\n" INDENT_END, (int) len_, name_)); 218 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "opening %.*s library\n" INDENT_END, (int) len_, name_));
215 STACK_CHECK( L); 219 STACK_CHECK( L, 0);
216 // open the library as if through require(), and create a global as well if necessary (the library table is left on the stack) 220 // open the library as if through require(), and create a global as well if necessary (the library table is left on the stack)
217 luaL_requiref( L, name_, libfunc, !isLanesCore); 221 luaL_requiref( L, name_, libfunc, !isLanesCore);
218 // lanes.core doesn't declare a global, so scan it here and now 222 // lanes.core doesn't declare a global, so scan it here and now
@@ -301,7 +305,7 @@ static char const* luaG_pushFQN( lua_State* L, int t, int last, size_t* length)
301{ 305{
302 int i = 1; 306 int i = 1;
303 luaL_Buffer b; 307 luaL_Buffer b;
304 STACK_CHECK( L); 308 STACK_CHECK( L, 0);
305 luaL_buffinit( L, &b); 309 luaL_buffinit( L, &b);
306 for( ; i < last; ++ i) 310 for( ; i < last; ++ i)
307 { 311 {
@@ -339,7 +343,7 @@ static void update_lookup_entry( lua_State* L, int _ctx_base, int _depth)
339 DEBUGSPEW_CODE( char const *newName); 343 DEBUGSPEW_CODE( char const *newName);
340 DEBUGSPEW_CODE( Universe* U = universe_get( L)); 344 DEBUGSPEW_CODE( Universe* U = universe_get( L));
341 345
342 STACK_CHECK( L); 346 STACK_CHECK( L, 0);
343 // first, raise an error if the function is already known 347 // first, raise an error if the function is already known
344 lua_pushvalue( L, -1); // ... {bfc} k o o 348 lua_pushvalue( L, -1); // ... {bfc} k o o
345 lua_rawget( L, dest); // ... {bfc} k o name? 349 lua_rawget( L, dest); // ... {bfc} k o name?
@@ -412,7 +416,7 @@ static void populate_func_lookup_table_recur( lua_State* L, int _ctx_base, int _
412 416
413 STACK_GROW( L, 6); 417 STACK_GROW( L, 6);
414 // slot _i contains a table where we search for functions (or a full userdata with a metatable) 418 // slot _i contains a table where we search for functions (or a full userdata with a metatable)
415 STACK_CHECK( L); // ... {_i} 419 STACK_CHECK( L, 0); // ... {_i}
416 420
417 // if object is a userdata, replace it by its metatable 421 // if object is a userdata, replace it by its metatable
418 if( lua_type( L, _i) == LUA_TUSERDATA) 422 if( lua_type( L, _i) == LUA_TUSERDATA)
@@ -530,8 +534,9 @@ void populate_func_lookup_table( lua_State* L, int _i, char const* name_)
530 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%p: populate_func_lookup_table('%s')\n" INDENT_END, L, name_ ? name_ : "NULL")); 534 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%p: populate_func_lookup_table('%s')\n" INDENT_END, L, name_ ? name_ : "NULL"));
531 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); 535 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth);
532 STACK_GROW( L, 3); 536 STACK_GROW( L, 3);
533 STACK_CHECK( L); 537 STACK_CHECK( L, 0);
534 lua_getfield( L, LUA_REGISTRYINDEX, LOOKUP_REGKEY); // {} 538 REGISTRY_GET( L, LOOKUP_REGKEY); // {}
539 STACK_MID( L, 1);
535 ASSERT_L( lua_istable( L, -1)); 540 ASSERT_L( lua_istable( L, -1));
536 if( lua_type( L, in_base) == LUA_TFUNCTION) // for example when a module is a simple function 541 if( lua_type( L, in_base) == LUA_TFUNCTION) // for example when a module is a simple function
537 { 542 {
@@ -585,12 +590,12 @@ void call_on_state_create( Universe* U, lua_State* L, lua_State* from_, LookupMo
585{ 590{
586 if( U->on_state_create_func != NULL) 591 if( U->on_state_create_func != NULL)
587 { 592 {
588 STACK_CHECK( L); 593 STACK_CHECK( L, 0);
589 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "calling on_state_create()\n" INDENT_END)); 594 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "calling on_state_create()\n" INDENT_END));
590 if( U->on_state_create_func != (lua_CFunction) initialize_on_state_create) 595 if( U->on_state_create_func != (lua_CFunction) initialize_on_state_create)
591 { 596 {
592 // C function: recreate a closure in the new state, bypassing the lookup scheme 597 // C function: recreate a closure in the new state, bypassing the lookup scheme
593 lua_pushcfunction( L, U->on_state_create_func); 598 lua_pushcfunction( L, U->on_state_create_func); // on_state_create()
594 } 599 }
595 else // Lua function located in the config table, copied when we opened "lanes.core" 600 else // Lua function located in the config table, copied when we opened "lanes.core"
596 { 601 {
@@ -600,10 +605,12 @@ void call_on_state_create( Universe* U, lua_State* L, lua_State* from_, LookupMo
600 // this doesn't count as an error though 605 // this doesn't count as an error though
601 return; 606 return;
602 } 607 }
603 lua_getfield( L, LUA_REGISTRYINDEX, CONFIG_REGKEY); 608 REGISTRY_GET( L, CONFIG_REGKEY); // {}
604 lua_getfield( L, -1, "on_state_create"); 609 STACK_MID( L, 1);
605 lua_remove( L, -2); 610 lua_getfield( L, -1, "on_state_create"); // {} on_state_create()
611 lua_remove( L, -2); // on_state_create()
606 } 612 }
613 STACK_MID( L, 1);
607 // capture error and raise it in caller state 614 // capture error and raise it in caller state
608 if( lua_pcall( L, 0, 0, 0) != LUA_OK) 615 if( lua_pcall( L, 0, 0, 0) != LUA_OK)
609 { 616 {
@@ -640,16 +647,16 @@ lua_State* luaG_newstate( Universe* U, lua_State* from_, char const* libs_)
640 } 647 }
641 648
642 STACK_GROW( L, 2); 649 STACK_GROW( L, 2);
650 STACK_CHECK_ABS( L, 0);
643 651
644 // copy the universe as a light userdata (only the master state holds the full userdata) 652 // copy the universe as a light userdata (only the master state holds the full userdata)
645 // that way, if Lanes is required in this new state, we'll know we are part of this universe 653 // that way, if Lanes is required in this new state, we'll know we are part of this universe
646 universe_store( L, U); 654 universe_store( L, U);
647 655 STACK_MID( L, 0);
648 STACK_CHECK( L);
649 656
650 // we'll need this every time we transfer some C function from/to this state 657 // we'll need this every time we transfer some C function from/to this state
651 lua_newtable( L); 658 REGISTRY_SET( L, LOOKUP_REGKEY, lua_newtable( L));
652 lua_setfield( L, LUA_REGISTRYINDEX, LOOKUP_REGKEY); 659 STACK_MID( L, 0);
653 660
654 // neither libs (not even 'base') nor special init func: we are done 661 // neither libs (not even 'base') nor special init func: we are done
655 if( libs_ == NULL && U->on_state_create_func == NULL) 662 if( libs_ == NULL && U->on_state_create_func == NULL)
@@ -724,7 +731,7 @@ lua_State* luaG_newstate( Universe* U, lua_State* from_, char const* libs_)
724 // will raise an error in from_ in case of problem 731 // will raise an error in from_ in case of problem
725 call_on_state_create( U, L, from_, eLM_LaneBody); 732 call_on_state_create( U, L, from_, eLM_LaneBody);
726 733
727 STACK_CHECK( L); 734 STACK_CHECK( L, 0);
728 // after all this, register everything we find in our name<->function database 735 // after all this, register everything we find in our name<->function database
729 lua_pushglobaltable( L); // Lua 5.2 no longer has LUA_GLOBALSINDEX: we must push globals table on the stack 736 lua_pushglobaltable( L); // Lua 5.2 no longer has LUA_GLOBALSINDEX: we must push globals table on the stack
730 populate_func_lookup_table( L, -1, NULL); 737 populate_func_lookup_table( L, -1, NULL);
@@ -769,7 +776,7 @@ static uint_t get_mt_id( Universe* U, lua_State* L, int i)
769 776
770 STACK_GROW( L, 3); 777 STACK_GROW( L, 3);
771 778
772 STACK_CHECK( L); 779 STACK_CHECK( L, 0);
773 push_registry_subtable( L, REG_MTID); 780 push_registry_subtable( L, REG_MTID);
774 lua_pushvalue( L, i); 781 lua_pushvalue( L, i);
775 lua_rawget( L, -2); 782 lua_rawget( L, -2);
@@ -839,7 +846,7 @@ static char const* find_lookup_name( lua_State* L, uint_t i, LookupMode mode_, c
839 DEBUGSPEW_CODE( Universe* const U = universe_get( L)); 846 DEBUGSPEW_CODE( Universe* const U = universe_get( L));
840 char const* fqn; 847 char const* fqn;
841 ASSERT_L( lua_isfunction( L, i) || lua_istable( L, i)); // ... v ... 848 ASSERT_L( lua_isfunction( L, i) || lua_istable( L, i)); // ... v ...
842 STACK_CHECK( L); 849 STACK_CHECK( L, 0);
843 STACK_GROW( L, 3); // up to 3 slots are necessary on error 850 STACK_GROW( L, 3); // up to 3 slots are necessary on error
844 if( mode_ == eLM_FromKeeper) 851 if( mode_ == eLM_FromKeeper)
845 { 852 {
@@ -859,7 +866,8 @@ static char const* find_lookup_name( lua_State* L, uint_t i, LookupMode mode_, c
859 else 866 else
860 { 867 {
861 // fetch the name from the source state's lookup table 868 // fetch the name from the source state's lookup table
862 lua_getfield( L, LUA_REGISTRYINDEX, LOOKUP_REGKEY); // ... v ... {} 869 REGISTRY_GET( L, LOOKUP_REGKEY); // ... v ... {}
870 STACK_MID( L, 1);
863 ASSERT_L( lua_istable( L, -1)); 871 ASSERT_L( lua_istable( L, -1));
864 lua_pushvalue( L, i); // ... v ... {} v 872 lua_pushvalue( L, i); // ... v ... {} v
865 lua_rawget( L, -2); // ... v ... {} "f.q.n" 873 lua_rawget( L, -2); // ... v ... {} "f.q.n"
@@ -915,7 +923,7 @@ static bool_t lookup_table( lua_State* L2, lua_State* L, uint_t i, LookupMode mo
915 return FALSE; 923 return FALSE;
916 } 924 }
917 // push the equivalent table in the destination's stack, retrieved from the lookup table 925 // push the equivalent table in the destination's stack, retrieved from the lookup table
918 STACK_CHECK( L2); // L // L2 926 STACK_CHECK( L2, 0); // L // L2
919 STACK_GROW( L2, 3); // up to 3 slots are necessary on error 927 STACK_GROW( L2, 3); // up to 3 slots are necessary on error
920 switch( mode_) 928 switch( mode_)
921 { 929 {
@@ -931,7 +939,8 @@ static bool_t lookup_table( lua_State* L2, lua_State* L, uint_t i, LookupMode mo
931 939
932 case eLM_LaneBody: 940 case eLM_LaneBody:
933 case eLM_FromKeeper: 941 case eLM_FromKeeper:
934 lua_getfield( L2, LUA_REGISTRYINDEX, LOOKUP_REGKEY); // {} 942 REGISTRY_GET( L2, LOOKUP_REGKEY); // {}
943 STACK_MID( L2, 1);
935 ASSERT_L( lua_istable( L2, -1)); 944 ASSERT_L( lua_istable( L2, -1));
936 lua_pushlstring( L2, fqn, len); // {} "f.q.n" 945 lua_pushlstring( L2, fqn, len); // {} "f.q.n"
937 lua_rawget( L2, -2); // {} t 946 lua_rawget( L2, -2); // {} t
@@ -987,7 +996,7 @@ static bool_t push_cached_table( lua_State* L2, uint_t L2_cache_i, lua_State* L,
987 996
988 ASSERT_L( L2_cache_i != 0); 997 ASSERT_L( L2_cache_i != 0);
989 STACK_GROW( L2, 3); 998 STACK_GROW( L2, 3);
990 STACK_CHECK( L2); 999 STACK_CHECK( L2, 0);
991 1000
992 // We don't need to use the from state ('L') in ID since the life span 1001 // We don't need to use the from state ('L') in ID since the life span
993 // is only for the duration of a copy (both states are locked). 1002 // is only for the duration of a copy (both states are locked).
@@ -1027,7 +1036,7 @@ static int discover_object_name_recur( lua_State* L, int shortest_, int depth_)
1027 return shortest_; 1036 return shortest_;
1028 } 1037 }
1029 STACK_GROW( L, 3); 1038 STACK_GROW( L, 3);
1030 STACK_CHECK( L); 1039 STACK_CHECK( L, 0);
1031 // stack top contains the table to search in 1040 // stack top contains the table to search in
1032 lua_pushvalue( L, -1); // o "r" {c} {fqn} ... {?} {?} 1041 lua_pushvalue( L, -1); // o "r" {c} {fqn} ... {?} {?}
1033 lua_rawget( L, cache); // o "r" {c} {fqn} ... {?} nil/1 1042 lua_rawget( L, cache); // o "r" {c} {fqn} ... {?} nil/1
@@ -1170,7 +1179,7 @@ int luaG_nameof( lua_State* L)
1170 } 1179 }
1171 1180
1172 STACK_GROW( L, 4); 1181 STACK_GROW( L, 4);
1173 STACK_CHECK( L); 1182 STACK_CHECK( L, 0);
1174 // this slot will contain the shortest name we found when we are done 1183 // this slot will contain the shortest name we found when we are done
1175 lua_pushnil( L); // o nil 1184 lua_pushnil( L); // o nil
1176 // push a cache that will contain all already visited tables 1185 // push a cache that will contain all already visited tables
@@ -1207,7 +1216,7 @@ static void lookup_native_func( lua_State* L2, lua_State* L, uint_t i, LookupMod
1207 size_t len; 1216 size_t len;
1208 char const* fqn = find_lookup_name( L, i, mode_, upName_, &len); 1217 char const* fqn = find_lookup_name( L, i, mode_, upName_, &len);
1209 // push the equivalent function in the destination's stack, retrieved from the lookup table 1218 // push the equivalent function in the destination's stack, retrieved from the lookup table
1210 STACK_CHECK( L2); // L // L2 1219 STACK_CHECK( L2, 0); // L // L2
1211 STACK_GROW( L2, 3); // up to 3 slots are necessary on error 1220 STACK_GROW( L2, 3); // up to 3 slots are necessary on error
1212 switch( mode_) 1221 switch( mode_)
1213 { 1222 {
@@ -1223,7 +1232,8 @@ static void lookup_native_func( lua_State* L2, lua_State* L, uint_t i, LookupMod
1223 1232
1224 case eLM_LaneBody: 1233 case eLM_LaneBody:
1225 case eLM_FromKeeper: 1234 case eLM_FromKeeper:
1226 lua_getfield( L2, LUA_REGISTRYINDEX, LOOKUP_REGKEY); // {} 1235 REGISTRY_GET( L2, LOOKUP_REGKEY); // {}
1236 STACK_MID( L2, 1);
1227 ASSERT_L( lua_istable( L2, -1)); 1237 ASSERT_L( lua_istable( L2, -1));
1228 lua_pushlstring( L2, fqn, len); // {} "f.q.n" 1238 lua_pushlstring( L2, fqn, len); // {} "f.q.n"
1229 lua_rawget( L2, -2); // {} f 1239 lua_rawget( L2, -2); // {} f
@@ -1290,7 +1300,7 @@ static void inter_copy_func( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_
1290 luaL_Buffer b; 1300 luaL_Buffer b;
1291 ASSERT_L( L2_cache_i != 0); // ... {cache} ... p 1301 ASSERT_L( L2_cache_i != 0); // ... {cache} ... p
1292 STACK_GROW( L, 2); 1302 STACK_GROW( L, 2);
1293 STACK_CHECK( L); 1303 STACK_CHECK( L, 0);
1294 1304
1295 // 'lua_dump()' needs the function at top of stack 1305 // 'lua_dump()' needs the function at top of stack
1296 // if already on top of the stack, no need to push again 1306 // if already on top of the stack, no need to push again
@@ -1447,7 +1457,7 @@ static void push_cached_func( Universe* U, lua_State* L2, uint_t L2_cache_i, lua
1447 1457
1448 // L2_cache[id_str]= function 1458 // L2_cache[id_str]= function
1449 // 1459 //
1450 STACK_CHECK( L2); 1460 STACK_CHECK( L2, 0);
1451 1461
1452 // We don't need to use the from state ('L') in ID since the life span 1462 // We don't need to use the from state ('L') in ID since the life span
1453 // is only for the duration of a copy (both states are locked). 1463 // is only for the duration of a copy (both states are locked).
@@ -1492,7 +1502,7 @@ static bool_t push_cached_metatable( Universe* U, lua_State* L2, uint_t L2_cache
1492 { 1502 {
1493 uint_t const mt_id = get_mt_id( U, L, -1); // Unique id for the metatable 1503 uint_t const mt_id = get_mt_id( U, L, -1); // Unique id for the metatable
1494 1504
1495 STACK_CHECK( L2); 1505 STACK_CHECK( L2, 0);
1496 STACK_GROW( L2, 4); 1506 STACK_GROW( L2, 4);
1497 // do we already know this metatable? 1507 // do we already know this metatable?
1498 push_registry_subtable( L2, REG_MTID); // rst 1508 push_registry_subtable( L2, REG_MTID); // rst
@@ -1605,8 +1615,8 @@ static bool_t inter_copy_one_( Universe* U, lua_State* L2, uint_t L2_cache_i, lu
1605 bool_t ret = TRUE; 1615 bool_t ret = TRUE;
1606 int val_type = lua_type( L, i); 1616 int val_type = lua_type( L, i);
1607 STACK_GROW( L2, 1); 1617 STACK_GROW( L2, 1);
1608 STACK_CHECK( L); // L // L2 1618 STACK_CHECK( L, 0); // L // L2
1609 STACK_CHECK( L2); // L // L2 1619 STACK_CHECK( L2, 0); // L // L2
1610 1620
1611 /* Skip the object if it has metatable with { __lanesignore = true } */ 1621 /* Skip the object if it has metatable with { __lanesignore = true } */
1612 if( lua_getmetatable( L, i)) // ... mt 1622 if( lua_getmetatable( L, i)) // ... mt
@@ -1618,6 +1628,7 @@ static bool_t inter_copy_one_( Universe* U, lua_State* L2, uint_t L2_cache_i, lu
1618 } 1628 }
1619 lua_pop( L, 2); // ... 1629 lua_pop( L, 2); // ...
1620 } 1630 }
1631 STACK_MID( L, 0);
1621 1632
1622 /* Lets push nil to L2 if the object should be ignored */ 1633 /* Lets push nil to L2 if the object should be ignored */
1623 switch( val_type) 1634 switch( val_type)
@@ -1786,7 +1797,7 @@ static bool_t inter_copy_one_( Universe* U, lua_State* L2, uint_t L2_cache_i, lu
1786 { 1797 {
1787 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "FUNCTION %s\n" INDENT_END, upName_)); 1798 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "FUNCTION %s\n" INDENT_END, upName_));
1788 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); 1799 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth);
1789 STACK_CHECK( L2); 1800 STACK_CHECK( L2, 0);
1790 push_cached_func( U, L2, L2_cache_i, L, i, mode_, upName_); 1801 push_cached_func( U, L2, L2_cache_i, L, i, mode_, upName_);
1791 STACK_END( L2, 1); 1802 STACK_END( L2, 1);
1792 DEBUGSPEW_CODE( -- U->debugspew_indent_depth); 1803 DEBUGSPEW_CODE( -- U->debugspew_indent_depth);
@@ -1800,8 +1811,8 @@ static bool_t inter_copy_one_( Universe* U, lua_State* L2, uint_t L2_cache_i, lu
1800 break; 1811 break;
1801 } 1812 }
1802 { 1813 {
1803 STACK_CHECK( L); 1814 STACK_CHECK( L, 0);
1804 STACK_CHECK( L2); 1815 STACK_CHECK( L2, 0);
1805 1816
1806 /* 1817 /*
1807 * 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?) 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?)
@@ -1943,8 +1954,8 @@ int luaG_inter_copy_package( Universe* U, lua_State* L, lua_State* L2, int packa
1943 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "luaG_inter_copy_package()\n" INDENT_END)); 1954 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "luaG_inter_copy_package()\n" INDENT_END));
1944 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); 1955 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth);
1945 // package 1956 // package
1946 STACK_CHECK( L); 1957 STACK_CHECK( L, 0);
1947 STACK_CHECK( L2); 1958 STACK_CHECK( L2, 0);
1948 package_idx_ = lua_absindex( L, package_idx_); 1959 package_idx_ = lua_absindex( L, package_idx_);
1949 if( lua_type( L, package_idx_) != LUA_TTABLE) 1960 if( lua_type( L, package_idx_) != LUA_TTABLE)
1950 { 1961 {
@@ -2009,7 +2020,7 @@ int luaG_new_require( lua_State* L)
2009 //char const* modname = luaL_checkstring( L, 1); 2020 //char const* modname = luaL_checkstring( L, 1);
2010 2021
2011 STACK_GROW( L, args + 1); 2022 STACK_GROW( L, args + 1);
2012 STACK_CHECK( L); 2023 STACK_CHECK( L, 0);
2013 2024
2014 lua_pushvalue( L, lua_upvalueindex( 1)); 2025 lua_pushvalue( L, lua_upvalueindex( 1));
2015 for( i = 1; i <= args; ++ i) 2026 for( i = 1; i <= args; ++ i)
@@ -2041,7 +2052,7 @@ int luaG_new_require( lua_State* L)
2041void serialize_require( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* L) 2052void serialize_require( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* L)
2042{ 2053{
2043 STACK_GROW( L, 1); 2054 STACK_GROW( L, 1);
2044 STACK_CHECK( L); 2055 STACK_CHECK( L, 0);
2045 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "serializing require()\n" INDENT_END)); 2056 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "serializing require()\n" INDENT_END));
2046 2057
2047 // Check 'require' is there and not already wrapped; if not, do nothing 2058 // Check 'require' is there and not already wrapped; if not, do nothing