diff options
Diffstat (limited to 'src/lanes.c')
-rw-r--r-- | src/lanes.c | 82 |
1 files changed, 57 insertions, 25 deletions
diff --git a/src/lanes.c b/src/lanes.c index 2b3d8ac..7bd29ee 100644 --- a/src/lanes.c +++ b/src/lanes.c | |||
@@ -52,7 +52,7 @@ | |||
52 | * ... | 52 | * ... |
53 | */ | 53 | */ |
54 | 54 | ||
55 | char const* VERSION = "3.5.0"; | 55 | char const* VERSION = "3.5.1"; |
56 | 56 | ||
57 | /* | 57 | /* |
58 | =============================================================================== | 58 | =============================================================================== |
@@ -92,8 +92,9 @@ THE SOFTWARE. | |||
92 | #include "threading.h" | 92 | #include "threading.h" |
93 | #include "tools.h" | 93 | #include "tools.h" |
94 | #include "keeper.h" | 94 | #include "keeper.h" |
95 | #include "lanes.h" | ||
95 | 96 | ||
96 | #if !((defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC)) | 97 | #if !(defined( PLATFORM_XBOX) || defined( PLATFORM_WIN32) || defined( PLATFORM_POCKETPC)) |
97 | # include <sys/time.h> | 98 | # include <sys/time.h> |
98 | #endif | 99 | #endif |
99 | 100 | ||
@@ -2580,6 +2581,26 @@ static const struct luaL_Reg lanes_functions [] = { | |||
2580 | {NULL, NULL} | 2581 | {NULL, NULL} |
2581 | }; | 2582 | }; |
2582 | 2583 | ||
2584 | |||
2585 | /* | ||
2586 | * minimal function registration for keepers, just so that we can populate the transfer databases with them | ||
2587 | * without recursively deadlocking ourselves during one-time inits | ||
2588 | */ | ||
2589 | void register_core_libfuncs_for_keeper( lua_State* L) | ||
2590 | { | ||
2591 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lanes.register_core_libfuncs_for_keeper()\n" INDENT_END)); | ||
2592 | DEBUGSPEW_CODE( ++ debugspew_indent_depth); | ||
2593 | STACK_GROW( L, 1); | ||
2594 | STACK_CHECK( L); | ||
2595 | lua_newtable( L); | ||
2596 | luaG_registerlibfuncs( L, lanes_functions); | ||
2597 | STACK_MID( L, 1); | ||
2598 | populate_func_lookup_table( L, -1, "lanes.core"); | ||
2599 | lua_pop( L, 1); | ||
2600 | STACK_END( L, 0); | ||
2601 | DEBUGSPEW_CODE( -- debugspew_indent_depth); | ||
2602 | } | ||
2603 | |||
2583 | /* | 2604 | /* |
2584 | * One-time initializations | 2605 | * One-time initializations |
2585 | */ | 2606 | */ |
@@ -2645,7 +2666,7 @@ static void init_once_LOCKED( lua_State* L, int const _on_state_create, int cons | |||
2645 | { | 2666 | { |
2646 | (void) luaL_error( L, "Unable to initialize: %s", err ); | 2667 | (void) luaL_error( L, "Unable to initialize: %s", err ); |
2647 | } | 2668 | } |
2648 | 2669 | ||
2649 | // Initialize 'timer_deep'; a common Linda object shared by all states | 2670 | // Initialize 'timer_deep'; a common Linda object shared by all states |
2650 | // | 2671 | // |
2651 | ASSERT_L( timer_deep == NULL); | 2672 | ASSERT_L( timer_deep == NULL); |
@@ -2842,43 +2863,54 @@ void EnableCrashingOnCrashes() | |||
2842 | #endif // PLATFORM_WIN32 | 2863 | #endif // PLATFORM_WIN32 |
2843 | } | 2864 | } |
2844 | 2865 | ||
2845 | int | 2866 | int LANES_API luaopen_lanes_core( lua_State* L) |
2846 | #if (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) | ||
2847 | __declspec(dllexport) | ||
2848 | #endif // (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) | ||
2849 | luaopen_lanes_core( lua_State* L) | ||
2850 | { | 2867 | { |
2851 | EnableCrashingOnCrashes(); | 2868 | EnableCrashingOnCrashes(); |
2852 | 2869 | ||
2853 | STACK_GROW( L, 3); | 2870 | STACK_GROW( L, 3); |
2854 | STACK_CHECK( L); | 2871 | STACK_CHECK( L); |
2855 | 2872 | ||
2856 | // sanity check: let's see if _"VERSION" matches what we we built against | ||
2857 | lua_getglobal( L, "_VERSION"); | ||
2858 | lua_pushstring( L, LUA_VERSION_NUM == 501 ? "Lua 5.1" : "Lua 5.2"); | ||
2859 | if( !lua_rawequal( L, -1, -2)) | ||
2860 | { | ||
2861 | return luaL_error( L, "Lanes is built against %s, but you are running %s", lua_tostring( L, -1), lua_tostring( L, -2)); | ||
2862 | } | ||
2863 | lua_pop( L, 2); | ||
2864 | |||
2865 | // Create main module interface table | 2873 | // Create main module interface table |
2866 | // we only have 1 closure, which must be called to configure Lanes | 2874 | // we only have 1 closure, which must be called to configure Lanes |
2867 | lua_newtable(L); | 2875 | lua_newtable(L); // M |
2868 | lua_pushvalue(L, 1); // module name | 2876 | lua_pushvalue(L, 1); // M "lanes.core" |
2869 | lua_pushvalue(L, -2); // module table | 2877 | lua_pushvalue(L, -2); // M "lanes.core" M |
2870 | lua_pushcclosure( L, LG_configure, 2); | 2878 | lua_pushcclosure( L, LG_configure, 2); // M LG_configure() |
2871 | if( s_initCount == 0) | 2879 | if( s_initCount == 0) |
2872 | { | 2880 | { |
2873 | lua_setfield( L, -2, "configure"); | 2881 | lua_setfield( L, -2, "configure"); // M |
2874 | } | 2882 | } |
2875 | else // already initialized: call it immediately and be done | 2883 | else // already initialized: call it immediately and be done |
2876 | { | 2884 | { |
2877 | lua_pushinteger( L, 666); // any value will do, it will be ignored | 2885 | // any parameter value will do, they will be ignored |
2878 | lua_pushnil( L); // almost idem | 2886 | lua_pushinteger( L, 666); // M LG_configure() 666 |
2879 | lua_call( L, 2, 0); | 2887 | lua_pushnil( L); // M LG_configure() 666 nil |
2888 | lua_call( L, 2, 0); // M | ||
2880 | } | 2889 | } |
2881 | 2890 | ||
2882 | STACK_END( L, 1); | 2891 | STACK_END( L, 1); |
2883 | return 1; | 2892 | return 1; |
2884 | } | 2893 | } |
2894 | |||
2895 | static int default_luaopen_lanes( lua_State* L) | ||
2896 | { | ||
2897 | int rc = luaL_loadfile( L, "lanes.lua") || lua_pcall( L, 0, 1, 0); | ||
2898 | if( rc != LUA_OK) | ||
2899 | { | ||
2900 | return luaL_error( L, "failed to initialize embedded Lanes"); | ||
2901 | } | ||
2902 | return 1; | ||
2903 | } | ||
2904 | |||
2905 | // call this instead of luaopen_lanes_core() when embedding Lua and Lanes in a custom application | ||
2906 | void LANES_API luaopen_lanes_embedded( lua_State* L, lua_CFunction _luaopen_lanes) | ||
2907 | { | ||
2908 | STACK_CHECK( L); | ||
2909 | // pre-require lanes.core so that when lanes.lua calls require "lanes.core" it finds it is already loaded | ||
2910 | luaL_requiref( L, "lanes.core", luaopen_lanes_core, 0); // ... lanes.core | ||
2911 | lua_pop( L, 1); // ... | ||
2912 | STACK_MID( L, 0); | ||
2913 | // call user-provided function that runs the chunk "lanes.lua" from wherever they stored it | ||
2914 | luaL_requiref( L, "lanes", _luaopen_lanes ? _luaopen_lanes : default_luaopen_lanes, 0); // ... lanes | ||
2915 | STACK_END( L, 1); | ||
2916 | } | ||