diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile | 37 | ||||
| -rw-r--r-- | src/keeper.c | 27 | ||||
| -rw-r--r-- | src/lanes-keeper.lua (renamed from src/keeper.lua) | 0 | ||||
| -rw-r--r-- | src/lanes.c | 10 | ||||
| -rw-r--r-- | src/lanes.lua | 4 |
5 files changed, 32 insertions, 46 deletions
diff --git a/src/Makefile b/src/Makefile index 03f5558..a16acce 100644 --- a/src/Makefile +++ b/src/Makefile | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | # | 1 | # |
| 2 | # Lanes/src/Makefile | 2 | # Lanes/src/Makefile |
| 3 | # | 3 | # |
| 4 | # make [LUA=... LUAC=...] Manual build | 4 | # make [LUA=...] Manual build |
| 5 | # make LUAROCKS=1 CFLAGS=... LIBFLAG=... LUA=... LUAC=... LuaRocks automated build | 5 | # make LUAROCKS=1 CFLAGS=... LIBFLAG=... LUA=... LuaRocks automated build |
| 6 | # | 6 | # |
| 7 | 7 | ||
| 8 | MODULE=lanes | 8 | MODULE=lanes |
| @@ -19,11 +19,10 @@ OPT_FLAGS=-O2 | |||
| 19 | # -O0 -g | 19 | # -O0 -g |
| 20 | 20 | ||
| 21 | LUA=lua | 21 | LUA=lua |
| 22 | LUAC=luac | ||
| 23 | 22 | ||
| 24 | _SO=.so | 23 | _SO=so |
| 25 | ifeq "$(findstring MINGW32,$(shell uname -s))" "MINGW32" | 24 | ifeq "$(findstring MINGW32,$(shell uname -s))" "MINGW32" |
| 26 | _SO=.dll | 25 | _SO=dll |
| 27 | endif | 26 | endif |
| 28 | 27 | ||
| 29 | ifeq "$(LUAROCKS)" "" | 28 | ifeq "$(LUAROCKS)" "" |
| @@ -116,32 +115,21 @@ ifeq "$(shell uname -s)" "BSD" | |||
| 116 | LIBS += -lpthread | 115 | LIBS += -lpthread |
| 117 | endif | 116 | endif |
| 118 | 117 | ||
| 118 | MODULE_DIR=$(MODULE) | ||
| 119 | |||
| 119 | #--- | 120 | #--- |
| 120 | all: lua51-$(MODULE)$(_SO) | 121 | all: $(MODULE)/core.$(_SO) |
| 121 | 122 | ||
| 122 | %.o: %.c *.h Makefile | 123 | %.o: %.c *.h Makefile |
| 123 | 124 | ||
| 124 | # Note: Don't put $(LUA_LIBS) ahead of $^; MSYS will not like that (I think) | 125 | # Note: Don't put $(LUA_LIBS) ahead of $^; MSYS will not like that (I think) |
| 125 | # | 126 | # |
| 126 | lua51-$(MODULE)$(_SO): $(OBJ) | 127 | $(MODULE_DIR)/core.$(_SO): $(OBJ) |
| 128 | mkdir -p $(MODULE_DIR) | ||
| 127 | $(CC) $(LIBFLAG) $^ $(LIBS) $(LUA_LIBS) -o $@ | 129 | $(CC) $(LIBFLAG) $^ $(LIBS) $(LUA_LIBS) -o $@ |
| 128 | 130 | ||
| 129 | clean: | 131 | clean: |
| 130 | -rm -rf lua51-$(MODULE)$(_SO) *.lch *.o *.tmp *.map | 132 | -rm -rf $(MODULE)/core.$(_SO) *.o *.map |
| 131 | |||
| 132 | lanes.o: keeper.lch | ||
| 133 | |||
| 134 | # Note: 'luac -o -' could be used on systems other than Windows (where pipes | ||
| 135 | # are binary). We need to support MinGW as well, so a temporary file. | ||
| 136 | # | ||
| 137 | # mode 1: embed bytecode version | ||
| 138 | #%.lch: %.lua | ||
| 139 | # $(LUAC) -o $@.tmp $< | ||
| 140 | # $(LUA) ../tools/bin2c.lua $@.tmp -o $@ | ||
| 141 | # -rm $@.tmp | ||
| 142 | # mode 2: embed text version (LuaJIT2-compatible) | ||
| 143 | %.lch: %.lua | ||
| 144 | $(LUA) ../tools/bin2c.lua $< -o $@ | ||
| 145 | 133 | ||
| 146 | #--- | 134 | #--- |
| 147 | # NSLU2 "slug" Linux ARM | 135 | # NSLU2 "slug" Linux ARM |
| @@ -166,10 +154,9 @@ win32: $(WIN32_LUA51)/include/lua.h | |||
| 166 | $(MAKE) build CC=$(MINGW_GCC) \ | 154 | $(MAKE) build CC=$(MINGW_GCC) \ |
| 167 | LUA_FLAGS=-I$(WIN32_LUA51)/include \ | 155 | LUA_FLAGS=-I$(WIN32_LUA51)/include \ |
| 168 | LUA_LIBS="-L$(WIN32_LUA51) -llua51" \ | 156 | LUA_LIBS="-L$(WIN32_LUA51) -llua51" \ |
| 169 | _SO=.dll \ | 157 | _SO=dll \ |
| 170 | SO_FLAGS=-shared \ | 158 | SO_FLAGS=-shared \ |
| 171 | LUA=lua51 \ | 159 | LUA=lua51 |
| 172 | LUAC=luac51 | ||
| 173 | 160 | ||
| 174 | $(WIN32_LUA51)/include/lua.h: | 161 | $(WIN32_LUA51)/include/lua.h: |
| 175 | @echo "Usage: make win32 WIN32_LUA51=<path of extracted LuaBinaries dll8 and dev packages>" | 162 | @echo "Usage: make win32 WIN32_LUA51=<path of extracted LuaBinaries dll8 and dev packages>" |
diff --git a/src/keeper.c b/src/keeper.c index 6f5bd95..2404520 100644 --- a/src/keeper.c +++ b/src/keeper.c | |||
| @@ -64,12 +64,6 @@ static struct s_Keeper *GKeepers = NULL; | |||
| 64 | static int GNbKeepers = 0; | 64 | static int GNbKeepers = 0; |
| 65 | 65 | ||
| 66 | /* | 66 | /* |
| 67 | * Lua code for the keeper states (baked in) | ||
| 68 | */ | ||
| 69 | static char const keeper_chunk[]= | ||
| 70 | #include "keeper.lch" | ||
| 71 | |||
| 72 | /* | ||
| 73 | * Initialize keeper states | 67 | * Initialize keeper states |
| 74 | * | 68 | * |
| 75 | * If there is a problem, return an error message (NULL for okay). | 69 | * If there is a problem, return an error message (NULL for okay). |
| @@ -95,26 +89,31 @@ char const* init_keepers( int const _nbKeepers, lua_CFunction _on_state_create) | |||
| 95 | if (!K) | 89 | if (!K) |
| 96 | return "out of memory"; | 90 | return "out of memory"; |
| 97 | 91 | ||
| 92 | STACK_CHECK( K) | ||
| 98 | // to see VM name in Decoda debugger | 93 | // to see VM name in Decoda debugger |
| 99 | lua_pushliteral( K, "Keeper #"); | 94 | lua_pushliteral( K, "Keeper #"); |
| 100 | lua_pushinteger( K, i + 1); | 95 | lua_pushinteger( K, i + 1); |
| 101 | lua_concat( K, 2); | 96 | lua_concat( K, 2); |
| 102 | lua_setglobal( K, "decoda_name"); | 97 | lua_setglobal( K, "decoda_name"); |
| 103 | 98 | ||
| 104 | // Read in the preloaded chunk (and run it) | 99 | // use package.loaders[2] to find keeper microcode |
| 105 | // | 100 | lua_getfield( K, LUA_GLOBALSINDEX, "package"); // package |
| 106 | if( luaL_loadbuffer( K, keeper_chunk, sizeof(keeper_chunk), "@keeper.lua")) | 101 | lua_getfield( K, -1, "loaders"); // package package.loaders |
| 107 | return "luaL_loadbuffer() failed"; // LUA_ERRMEM | 102 | lua_rawgeti( K, -1, 2); // package package.loaders package.loaders[2] |
| 108 | 103 | lua_pushliteral( K, "lanes-keeper"); // package package.loaders package.loaders[2] "lanes-keeper" | |
| 109 | if( lua_pcall( K, 0 /*args*/, 0 /*results*/, 0 /*errfunc*/)) | 104 | STACK_MID( K, 4); |
| 105 | // first pcall loads lanes-keeper.lua, second one runs the chunk | ||
| 106 | if( lua_pcall( K, 1 /*args*/, 1 /*results*/, 0 /*errfunc*/) || lua_pcall( K, 0 /*args*/, 0 /*results*/, 0 /*errfunc*/)) | ||
| 110 | { | 107 | { |
| 111 | // LUA_ERRRUN / LUA_ERRMEM / LUA_ERRERR | 108 | // LUA_ERRRUN / LUA_ERRMEM / LUA_ERRERR |
| 112 | // | 109 | // |
| 113 | char const* err = lua_tostring( K, -1); | 110 | char const* err = lua_tostring( K, -1); |
| 114 | assert( err); | 111 | assert( err); |
| 115 | return err; | 112 | return err; |
| 116 | } | 113 | } // package package.loaders |
| 117 | 114 | STACK_MID( K, 2); | |
| 115 | lua_pop( K, 2); | ||
| 116 | STACK_END( K, 0) | ||
| 118 | MUTEX_INIT( &GKeepers[i].lock_); | 117 | MUTEX_INIT( &GKeepers[i].lock_); |
| 119 | GKeepers[i].L = K; | 118 | GKeepers[i].L = K; |
| 120 | //GKeepers[i].count = 0; | 119 | //GKeepers[i].count = 0; |
diff --git a/src/keeper.lua b/src/lanes-keeper.lua index 1f17599..1f17599 100644 --- a/src/keeper.lua +++ b/src/lanes-keeper.lua | |||
diff --git a/src/lanes.c b/src/lanes.c index 3e906c0..300c924 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.4"; | 54 | char const* VERSION = "3.1.5"; |
| 55 | 55 | ||
| 56 | /* | 56 | /* |
| 57 | =============================================================================== | 57 | =============================================================================== |
| @@ -868,7 +868,7 @@ static void linda_id( lua_State *L, char const * const which) | |||
| 868 | // in other words, forever. | 868 | // in other words, forever. |
| 869 | lua_pushnil( L); | 869 | lua_pushnil( L); |
| 870 | // other idfuncs must push a string naming the module they come from | 870 | // other idfuncs must push a string naming the module they come from |
| 871 | //lua_pushliteral( L, "lua51-lanes"); | 871 | //lua_pushliteral( L, "lanes.core"); |
| 872 | } | 872 | } |
| 873 | } | 873 | } |
| 874 | 874 | ||
| @@ -1697,11 +1697,11 @@ LUAG_FUNC( thread_new ) | |||
| 1697 | 1697 | ||
| 1698 | // modules to require in the target lane *before* the function is transfered! | 1698 | // modules to require in the target lane *before* the function is transfered! |
| 1699 | 1699 | ||
| 1700 | //start by requiring lua51-lanes, since it is a bit special | 1700 | //start by requiring lanes.core, since it is a bit special |
| 1701 | // it is not fatal if 'require' isn't loaded, just ignore (may cause function transfer errors later on if the lane pulls the lanes module itself) | 1701 | // it is not fatal if 'require' isn't loaded, just ignore (may cause function transfer errors later on if the lane pulls the lanes module itself) |
| 1702 | STACK_CHECK(L) | 1702 | STACK_CHECK(L) |
| 1703 | STACK_CHECK(L2) | 1703 | STACK_CHECK(L2) |
| 1704 | lua_pushliteral( L, "lua51-lanes"); | 1704 | lua_pushliteral( L, "lanes.core"); |
| 1705 | require_one_module( L, L2, FALSE); | 1705 | require_one_module( L, L2, FALSE); |
| 1706 | lua_pop( L, 1); | 1706 | lua_pop( L, 1); |
| 1707 | STACK_END(L2,0) | 1707 | STACK_END(L2,0) |
| @@ -2510,7 +2510,7 @@ int | |||
| 2510 | #if (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) | 2510 | #if (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) |
| 2511 | __declspec(dllexport) | 2511 | __declspec(dllexport) |
| 2512 | #endif // (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) | 2512 | #endif // (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) |
| 2513 | luaopen_lanes( lua_State *L ) | 2513 | luaopen_lanes_core( lua_State *L ) |
| 2514 | { | 2514 | { |
| 2515 | // Create main module interface table | 2515 | // Create main module interface table |
| 2516 | // we only have 1 closure, which must be called to configure Lanes | 2516 | // we only have 1 closure, which must be called to configure Lanes |
diff --git a/src/lanes.lua b/src/lanes.lua index bd66e6c..8cd3737 100644 --- a/src/lanes.lua +++ b/src/lanes.lua | |||
| @@ -55,10 +55,10 @@ if _params.on_state_create and (type( _params.on_state_create) ~= "function") th | |||
| 55 | error( "Bad on_state_create: " .. tostring( _params.on_state_create), 2) | 55 | error( "Bad on_state_create: " .. tostring( _params.on_state_create), 2) |
| 56 | end | 56 | end |
| 57 | 57 | ||
| 58 | local mm = require "lua51-lanes" | 58 | local mm = require "lanes.core" |
| 59 | assert( type(mm)=="table" ) | 59 | assert( type(mm)=="table" ) |
| 60 | 60 | ||
| 61 | -- configure() is available only the first time lua51-lanes is required process-wide, and we *must* call it to have the other functions in the interface | 61 | -- configure() is available only the first time lanes.core is required process-wide, and we *must* call it to have the other functions in the interface |
| 62 | if mm.configure then mm.configure( _params.nb_keepers, _params.on_state_create) end | 62 | if mm.configure then mm.configure( _params.nb_keepers, _params.on_state_create) end |
| 63 | 63 | ||
| 64 | local thread_new = assert(mm.thread_new) | 64 | local thread_new = assert(mm.thread_new) |
