diff options
Diffstat (limited to 'src/lanes.c')
-rw-r--r-- | src/lanes.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/src/lanes.c b/src/lanes.c index 360990a..84f23e3 100644 --- a/src/lanes.c +++ b/src/lanes.c | |||
@@ -51,7 +51,7 @@ | |||
51 | * ... | 51 | * ... |
52 | */ | 52 | */ |
53 | 53 | ||
54 | char const* VERSION = "3.1.5"; | 54 | char const* VERSION = "3.1.6"; |
55 | 55 | ||
56 | /* | 56 | /* |
57 | =============================================================================== | 57 | =============================================================================== |
@@ -928,7 +928,7 @@ LUAG_FUNC( set_finalizer ) | |||
928 | // | 928 | // |
929 | push_registry_table( L, FINALIZER_REG_KEY, TRUE /*do create if none*/ ); | 929 | push_registry_table( L, FINALIZER_REG_KEY, TRUE /*do create if none*/ ); |
930 | 930 | ||
931 | lua_pushinteger( L, lua_objlen(L,-1)+1 ); | 931 | lua_pushinteger( L, lua_rawlen(L,-1)+1 ); |
932 | lua_pushvalue( L, 1 ); // copy of the function | 932 | lua_pushvalue( L, 1 ); // copy of the function |
933 | lua_settable( L, -3 ); | 933 | lua_settable( L, -3 ); |
934 | 934 | ||
@@ -966,7 +966,8 @@ static int run_finalizers( lua_State *L, int lua_rc ) | |||
966 | 966 | ||
967 | // [-1]: { func [, ...] } | 967 | // [-1]: { func [, ...] } |
968 | // | 968 | // |
969 | for( n= (unsigned int)lua_objlen(L,-1); n>0; n-- ) { | 969 | for( n = (unsigned int)lua_rawlen( L, -1); n > 0; -- n) |
970 | { | ||
970 | unsigned args= 0; | 971 | unsigned args= 0; |
971 | lua_pushinteger( L,n ); | 972 | lua_pushinteger( L,n ); |
972 | lua_gettable( L, -2 ); | 973 | lua_gettable( L, -2 ); |
@@ -1686,6 +1687,7 @@ LUAG_FUNC( thread_new ) | |||
1686 | if (!L2) luaL_error( L, "'luaL_newstate()' failed; out of memory" ); | 1687 | if (!L2) luaL_error( L, "'luaL_newstate()' failed; out of memory" ); |
1687 | 1688 | ||
1688 | STACK_GROW( L, 2); | 1689 | STACK_GROW( L, 2); |
1690 | STACK_GROW( L2, 3); | ||
1689 | 1691 | ||
1690 | ASSERT_L( lua_gettop(L2) == 0); | 1692 | ASSERT_L( lua_gettop(L2) == 0); |
1691 | 1693 | ||
@@ -1769,13 +1771,15 @@ LUAG_FUNC( thread_new ) | |||
1769 | luaL_error( L, "Expected table, got %s", luaL_typename(L,glob)); | 1771 | luaL_error( L, "Expected table, got %s", luaL_typename(L,glob)); |
1770 | 1772 | ||
1771 | lua_pushnil( L); | 1773 | lua_pushnil( L); |
1774 | lua_pushglobaltable( L2); // Lua 5.2 wants us to push the globals table on the stack | ||
1772 | while( lua_next( L, glob)) | 1775 | while( lua_next( L, glob)) |
1773 | { | 1776 | { |
1774 | luaG_inter_copy( L, L2, 2); // moves the key/value pair to the L2 stack | 1777 | luaG_inter_copy( L, L2, 2); // moves the key/value pair to the L2 stack |
1775 | // assign it in the globals table | 1778 | // assign it in L2's globals table |
1776 | lua_rawset( L2, LUA_GLOBALSINDEX); | 1779 | lua_rawset( L2, -3); |
1777 | lua_pop( L, 1); | 1780 | lua_pop( L, 1); |
1778 | } | 1781 | } |
1782 | lua_pop( L2, 1); | ||
1779 | 1783 | ||
1780 | STACK_END(L2, 0) | 1784 | STACK_END(L2, 0) |
1781 | STACK_END(L, 0) | 1785 | STACK_END(L, 0) |
@@ -1845,7 +1849,7 @@ LUAG_FUNC( thread_new ) | |||
1845 | // Clear environment for the userdata | 1849 | // Clear environment for the userdata |
1846 | // | 1850 | // |
1847 | lua_newtable( L); | 1851 | lua_newtable( L); |
1848 | lua_setfenv( L, -2); | 1852 | lua_setuservalue( L, -2); |
1849 | 1853 | ||
1850 | // Place 's' in registry, for 'cancel_test()' (even if 'cs'==0 we still | 1854 | // Place 's' in registry, for 'cancel_test()' (even if 'cs'==0 we still |
1851 | // do cancel tests at pending send/receive). | 1855 | // do cancel tests at pending send/receive). |
@@ -2134,7 +2138,7 @@ LUAG_FUNC( thread_index) | |||
2134 | // first, check that we don't already have an environment that holds the requested value | 2138 | // first, check that we don't already have an environment that holds the requested value |
2135 | { | 2139 | { |
2136 | // If key is found in the environment, return it | 2140 | // If key is found in the environment, return it |
2137 | lua_getfenv( L, UD); | 2141 | lua_getuservalue( L, UD); |
2138 | lua_pushvalue( L, KEY); | 2142 | lua_pushvalue( L, KEY); |
2139 | lua_rawget( L, ENV); | 2143 | lua_rawget( L, ENV); |
2140 | if( !lua_isnil( L, -1)) | 2144 | if( !lua_isnil( L, -1)) |
@@ -2324,7 +2328,7 @@ LUAG_FUNC( wakeup_conv ) | |||
2324 | /*---=== Module linkage ===--- | 2328 | /*---=== Module linkage ===--- |
2325 | */ | 2329 | */ |
2326 | 2330 | ||
2327 | static const struct luaL_reg lanes_functions [] = { | 2331 | static const struct luaL_Reg lanes_functions [] = { |
2328 | {"linda", LG_linda}, | 2332 | {"linda", LG_linda}, |
2329 | {"now_secs", LG_now_secs}, | 2333 | {"now_secs", LG_now_secs}, |
2330 | {"wakeup_conv", LG_wakeup_conv}, | 2334 | {"wakeup_conv", LG_wakeup_conv}, |
@@ -2485,7 +2489,8 @@ LUAG_FUNC( configure ) | |||
2485 | // remove configure() (this function) from the module interface | 2489 | // remove configure() (this function) from the module interface |
2486 | lua_pushnil( L); | 2490 | lua_pushnil( L); |
2487 | lua_setfield( L, -2, "configure"); | 2491 | lua_setfield( L, -2, "configure"); |
2488 | luaL_register(L, NULL, lanes_functions); | 2492 | // add functions to the module's table |
2493 | luaG_registerlibfuncs(L, lanes_functions); | ||
2489 | 2494 | ||
2490 | // metatable for threads | 2495 | // metatable for threads |
2491 | // contains keys: { __gc, __index, cached_error, cached_tostring, cancel, join } | 2496 | // contains keys: { __gc, __index, cached_error, cached_tostring, cancel, join } |
@@ -2495,10 +2500,10 @@ LUAG_FUNC( configure ) | |||
2495 | lua_setfield( L, -2, "__gc"); | 2500 | lua_setfield( L, -2, "__gc"); |
2496 | lua_pushcfunction( L, LG_thread_index); | 2501 | lua_pushcfunction( L, LG_thread_index); |
2497 | lua_setfield( L, -2, "__index"); | 2502 | lua_setfield( L, -2, "__index"); |
2498 | lua_getfield( L, LUA_GLOBALSINDEX, "error"); | 2503 | lua_getglobal( L, "error"); |
2499 | ASSERT_L( lua_isfunction( L, -1)); | 2504 | ASSERT_L( lua_isfunction( L, -1)); |
2500 | lua_setfield( L, -2, "cached_error"); | 2505 | lua_setfield( L, -2, "cached_error"); |
2501 | lua_getfield( L, LUA_GLOBALSINDEX, "tostring"); | 2506 | lua_getglobal( L, "tostring"); |
2502 | ASSERT_L( lua_isfunction( L, -1)); | 2507 | ASSERT_L( lua_isfunction( L, -1)); |
2503 | lua_setfield( L, -2, "cached_tostring"); | 2508 | lua_setfield( L, -2, "cached_tostring"); |
2504 | lua_pushcfunction( L, LG_thread_join); | 2509 | lua_pushcfunction( L, LG_thread_join); |
@@ -2526,10 +2531,12 @@ LUAG_FUNC( configure ) | |||
2526 | // register all native functions found in that module in the transferable functions database | 2531 | // register all native functions found in that module in the transferable functions database |
2527 | // we process it before _G because we don't want to find the module when scanning _G (this would generate longer names) | 2532 | // we process it before _G because we don't want to find the module when scanning _G (this would generate longer names) |
2528 | populate_func_lookup_table( L, -1, name); | 2533 | populate_func_lookup_table( L, -1, name); |
2534 | lua_pop( L, 1); | ||
2529 | // record all existing C/JIT-fast functions | 2535 | // record all existing C/JIT-fast functions |
2530 | populate_func_lookup_table( L, LUA_GLOBALSINDEX, NULL); | 2536 | lua_pushglobaltable( L); // Lua 5.2 no longer has LUA_GLOBALSINDEX: we must push globals table on the stack |
2537 | populate_func_lookup_table( L, -1, NULL); | ||
2538 | lua_pop( L, 1); // done with globals table, pop it | ||
2531 | // Return nothing | 2539 | // Return nothing |
2532 | lua_pop( L, 1); | ||
2533 | return 0; | 2540 | return 0; |
2534 | } | 2541 | } |
2535 | 2542 | ||