aboutsummaryrefslogtreecommitdiff
path: root/src/tools.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools.c')
-rw-r--r--src/tools.c47
1 files changed, 16 insertions, 31 deletions
diff --git a/src/tools.c b/src/tools.c
index c13d80d..0ef779a 100644
--- a/src/tools.c
+++ b/src/tools.c
@@ -140,7 +140,7 @@ void initialize_on_state_create( Universe* U, lua_State* L)
140// ################################################################################################ 140// ################################################################################################
141 141
142// just like lua_xmove, args are (from, to) 142// just like lua_xmove, args are (from, to)
143void luaG_copy_one_time_settings( Universe* U, lua_State* L, lua_State* L2) 143static void copy_one_time_settings( Universe* U, lua_State* L, lua_State* L2)
144{ 144{
145 STACK_GROW( L, 1); 145 STACK_GROW( L, 1);
146 // copy settings from from source to destination registry 146 // copy settings from from source to destination registry
@@ -213,11 +213,6 @@ static void open1lib( Universe* U, lua_State* L, char const* name_, size_t len_,
213 bool_t const isLanesCore = (libfunc == require_lanes_core) ? TRUE : FALSE; // don't want to create a global for "lanes.core" 213 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_)); 214 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "opening %.*s library\n" INDENT_END, (int) len_, name_));
215 STACK_CHECK( L); 215 STACK_CHECK( L);
216 if( isLanesCore == TRUE)
217 {
218 // copy settings from from source to destination registry
219 luaG_copy_one_time_settings( U, from_, L);
220 }
221 // open the library as if through require(), and create a global as well if necessary (the library table is left on the stack) 216 // open the library as if through require(), and create a global as well if necessary (the library table is left on the stack)
222 luaL_requiref( L, name_, libfunc, !isLanesCore); 217 luaL_requiref( L, name_, libfunc, !isLanesCore);
223 // lanes.core doesn't declare a global, so scan it here and now 218 // lanes.core doesn't declare a global, so scan it here and now
@@ -666,10 +661,14 @@ lua_State* luaG_newstate( Universe* U, lua_State* from_, char const* libs_)
666 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "luaG_newstate()\n" INDENT_END)); 661 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "luaG_newstate()\n" INDENT_END));
667 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); 662 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth);
668 663
664 // copy settings (for example because it may contain a Lua on_state_create function)
665 copy_one_time_settings( U, from_, L);
666
669 // 'lua.c' stops GC during initialization so perhaps its a good idea. :) 667 // 'lua.c' stops GC during initialization so perhaps its a good idea. :)
670 lua_gc( L, LUA_GCSTOP, 0); 668 lua_gc( L, LUA_GCSTOP, 0);
671 669
672 // Anything causes 'base' to be taken in 670
671 // Anything causes 'base' to be taken in
673 // 672 //
674 if( libs_ != NULL) 673 if( libs_ != NULL)
675 { 674 {
@@ -1657,8 +1656,7 @@ static bool_t inter_copy_one_( Universe* U, lua_State* L2, uint_t L2_cache_i, lu
1657 ret = FALSE; 1656 ret = FALSE;
1658 break; 1657 break;
1659 } 1658 }
1660 /* Allow only deep userdata entities to be copied across 1659 // Allow only deep userdata entities to be copied across
1661 */
1662 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "USERDATA\n" INDENT_END)); 1660 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "USERDATA\n" INDENT_END));
1663 if( !copydeep( U, L, L2, i, mode_)) 1661 if( !copydeep( U, L, L2, i, mode_))
1664 { 1662 {
@@ -1694,29 +1692,16 @@ static bool_t inter_copy_one_( Universe* U, lua_State* L2, uint_t L2_cache_i, lu
1694 } 1692 }
1695 lua_pop( L, 2); // ... 1693 lua_pop( L, 2); // ...
1696 } 1694 }
1695
1696 // Not a deep or clonable full userdata
1697 if( U->demoteFullUserdata) // attempt demotion to light userdata
1697 { 1698 {
1698 // Not a deep or clonable full userdata 1699 void* lud = lua_touserdata( L, i);
1699 bool_t demote = FALSE; 1700 lua_pushlightuserdata( L2, lud);
1700 lua_getfield( L, LUA_REGISTRYINDEX, CONFIG_REGKEY); 1701 }
1701 if( lua_istable( L, -1)) // should not happen, but who knows... 1702 else // raise an error
1702 { 1703 {
1703 lua_getfield( L, -1, "demote_full_userdata"); 1704 (void) luaL_error( L, "can't copy non-deep full userdata across lanes");
1704 demote = lua_toboolean( L, -1);
1705 lua_pop( L, 2);
1706 }
1707 else
1708 {
1709 lua_pop( L, 1);
1710 }
1711 if( demote) // attempt demotion to light userdata
1712 {
1713 void* lud = lua_touserdata( L, i);
1714 lua_pushlightuserdata( L2, lud);
1715 }
1716 else // raise an error
1717 {
1718 (void) luaL_error( L, "can't copy non-deep full userdata across lanes");
1719 }
1720 } 1705 }
1721 } 1706 }
1722 break; 1707 break;