diff options
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | msvc/llthreads.vcproj | 12 | ||||
-rw-r--r-- | src/l52util.c | 5 | ||||
-rw-r--r-- | src/l52util.h | 5 | ||||
-rw-r--r-- | src/llthread.c | 24 |
5 files changed, 29 insertions, 18 deletions
@@ -5,6 +5,7 @@ lua-llthreads2 | |||
5 | This is full dropin replacement for [llthreads](https://github.com/Neopallium/lua-llthreads) library. | 5 | This is full dropin replacement for [llthreads](https://github.com/Neopallium/lua-llthreads) library. |
6 | 6 | ||
7 | ##Incompatibility list with origin llthreads library | 7 | ##Incompatibility list with origin llthreads library |
8 | * does not support Lua 5.0 | ||
8 | * does not support ffi interface (use Lua C API for LuaJIT) | 9 | * does not support ffi interface (use Lua C API for LuaJIT) |
9 | * returns nil instead of false on error | 10 | * returns nil instead of false on error |
10 | * start method returns self instead of true on success | 11 | * start method returns self instead of true on success |
diff --git a/msvc/llthreads.vcproj b/msvc/llthreads.vcproj index 7b2a0e2..6f6c5bd 100644 --- a/msvc/llthreads.vcproj +++ b/msvc/llthreads.vcproj | |||
@@ -41,7 +41,7 @@ | |||
41 | <Tool | 41 | <Tool |
42 | Name="VCCLCompilerTool" | 42 | Name="VCCLCompilerTool" |
43 | Optimization="0" | 43 | Optimization="0" |
44 | AdditionalIncludeDirectories="$(LUA_DIR)\include" | 44 | AdditionalIncludeDirectories="$(LUA_DIR_5_2)\include" |
45 | PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LLTHREADS_EXPORTS" | 45 | PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LLTHREADS_EXPORTS" |
46 | MinimalRebuild="true" | 46 | MinimalRebuild="true" |
47 | BasicRuntimeChecks="3" | 47 | BasicRuntimeChecks="3" |
@@ -62,9 +62,9 @@ | |||
62 | <Tool | 62 | <Tool |
63 | Name="VCLinkerTool" | 63 | Name="VCLinkerTool" |
64 | AdditionalOptions="/EXPORT:luaopen_llthreads" | 64 | AdditionalOptions="/EXPORT:luaopen_llthreads" |
65 | AdditionalDependencies="lua5.1.lib" | 65 | AdditionalDependencies="lua52.lib" |
66 | LinkIncremental="2" | 66 | LinkIncremental="2" |
67 | AdditionalLibraryDirectories="$(LUA_DIR)\lib" | 67 | AdditionalLibraryDirectories="$(LUA_DIR_5_2)\lib" |
68 | GenerateDebugInformation="true" | 68 | GenerateDebugInformation="true" |
69 | SubSystem="2" | 69 | SubSystem="2" |
70 | TargetMachine="1" | 70 | TargetMachine="1" |
@@ -118,7 +118,7 @@ | |||
118 | Name="VCCLCompilerTool" | 118 | Name="VCCLCompilerTool" |
119 | Optimization="2" | 119 | Optimization="2" |
120 | EnableIntrinsicFunctions="true" | 120 | EnableIntrinsicFunctions="true" |
121 | AdditionalIncludeDirectories="$(LUA_DIR)\include" | 121 | AdditionalIncludeDirectories="$(LUA_DIR_5_2)\include" |
122 | PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;LLTHREADS_EXPORTS" | 122 | PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;LLTHREADS_EXPORTS" |
123 | RuntimeLibrary="2" | 123 | RuntimeLibrary="2" |
124 | EnableFunctionLevelLinking="true" | 124 | EnableFunctionLevelLinking="true" |
@@ -137,9 +137,9 @@ | |||
137 | /> | 137 | /> |
138 | <Tool | 138 | <Tool |
139 | Name="VCLinkerTool" | 139 | Name="VCLinkerTool" |
140 | AdditionalDependencies="lua5.1.lib" | 140 | AdditionalDependencies="lua52.lib" |
141 | LinkIncremental="1" | 141 | LinkIncremental="1" |
142 | AdditionalLibraryDirectories="$(LUA_DIR)\lib" | 142 | AdditionalLibraryDirectories="$(LUA_DIR_5_2)\lib" |
143 | GenerateDebugInformation="true" | 143 | GenerateDebugInformation="true" |
144 | SubSystem="2" | 144 | SubSystem="2" |
145 | OptimizeReferences="2" | 145 | OptimizeReferences="2" |
diff --git a/src/l52util.c b/src/l52util.c index 592c1d1..0b40c3e 100644 --- a/src/l52util.c +++ b/src/l52util.c | |||
@@ -43,6 +43,11 @@ void lua_rawsetp (lua_State *L, int index, const void *p){ | |||
43 | lua_rawset(L, index); | 43 | lua_rawset(L, index); |
44 | } | 44 | } |
45 | 45 | ||
46 | void lutil_require(lua_State *L, const char* name, lua_CFunction fn, int glb) { | ||
47 | // @fixme generate error if we can not load module | ||
48 | lua_cpcall(L, fn, NULL); | ||
49 | } | ||
50 | |||
46 | #endif | 51 | #endif |
47 | 52 | ||
48 | int lutil_newmetatablep (lua_State *L, const void *p) { | 53 | int lutil_newmetatablep (lua_State *L, const void *p) { |
diff --git a/src/l52util.h b/src/l52util.h index f4f0497..94f1bfa 100644 --- a/src/l52util.h +++ b/src/l52util.h | |||
@@ -18,6 +18,9 @@ int luaL_typerror (lua_State *L, int narg, const char *tname); | |||
18 | 18 | ||
19 | void luaL_register (lua_State *L, const char *libname, const luaL_Reg *l); | 19 | void luaL_register (lua_State *L, const char *libname, const luaL_Reg *l); |
20 | 20 | ||
21 | |||
22 | #define lutil_require luaL_requiref | ||
23 | |||
21 | #else // lua 5.1 | 24 | #else // lua 5.1 |
22 | 25 | ||
23 | // functions form lua 5.2 | 26 | // functions form lua 5.2 |
@@ -29,6 +32,8 @@ void lua_rawgetp (lua_State *L, int index, const void *p); | |||
29 | void lua_rawsetp (lua_State *L, int index, const void *p); | 32 | void lua_rawsetp (lua_State *L, int index, const void *p); |
30 | void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup); | 33 | void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup); |
31 | 34 | ||
35 | void lutil_require(lua_State *L, const char* name, lua_CFunction fn, int glb); | ||
36 | |||
32 | #endif | 37 | #endif |
33 | 38 | ||
34 | int lutil_newmetatablep (lua_State *L, const void *p); | 39 | int lutil_newmetatablep (lua_State *L, const void *p); |
diff --git a/src/llthread.c b/src/llthread.c index 6cb437b..0449ea9 100644 --- a/src/llthread.c +++ b/src/llthread.c | |||
@@ -308,26 +308,26 @@ typedef struct llthread_t { | |||
308 | 308 | ||
309 | static void open_thread_libs(lua_State *L){ | 309 | static void open_thread_libs(lua_State *L){ |
310 | #ifdef LLTHREAD_REGISTER_STD_LIBRARY | 310 | #ifdef LLTHREAD_REGISTER_STD_LIBRARY |
311 | # define L_REGLIB(L, name) lua_pushcfunction(L, luaopen_##name); lua_setfield(L, -2, #name) | 311 | # define L_REGLIB(L, name, G) lua_pushcfunction(L, luaopen_##name); lua_setfield(L, -2, #name) |
312 | #else | 312 | #else |
313 | # define L_REGLIB(L, name) lua_cpcall(L, luaopen_##name, 0) | 313 | # define L_REGLIB(L, name, G) lutil_require(L, #name, luaopen_##name, G) |
314 | #endif | 314 | #endif |
315 | 315 | ||
316 | int top = lua_gettop(L); | 316 | int top = lua_gettop(L); |
317 | lua_cpcall(L, luaopen_base, 0); | 317 | lutil_require(L, "_G", luaopen_base, 1); |
318 | lua_cpcall(L, luaopen_package, 0); | 318 | lutil_require(L, "package", luaopen_package, 1); |
319 | lua_settop(L, top); | 319 | lua_settop(L, top); |
320 | 320 | ||
321 | /* get package.preload */ | 321 | /* get package.preload */ |
322 | lua_getglobal(L, "package"); lua_getfield(L, -1, "preload"); lua_remove(L, -2); | 322 | lua_getglobal(L, "package"); lua_getfield(L, -1, "preload"); lua_remove(L, -2); |
323 | 323 | ||
324 | L_REGLIB(L, io ); | 324 | L_REGLIB(L, io, 1); |
325 | L_REGLIB(L, os ); | 325 | L_REGLIB(L, os, 1); |
326 | L_REGLIB(L, math ); | 326 | L_REGLIB(L, math, 1); |
327 | L_REGLIB(L, table ); | 327 | L_REGLIB(L, table, 1); |
328 | L_REGLIB(L, debug ); | 328 | L_REGLIB(L, debug, 1); |
329 | L_REGLIB(L, string ); | 329 | L_REGLIB(L, string, 1); |
330 | L_REGLIB(L, llthreads ); | 330 | L_REGLIB(L, llthreads, 0); |
331 | 331 | ||
332 | lua_settop(L, top); | 332 | lua_settop(L, top); |
333 | #undef L_REGLIB | 333 | #undef L_REGLIB |
@@ -446,7 +446,7 @@ static int llthread_start(llthread_t *this, int start_detached) { | |||
446 | #ifndef USE_PTHREAD | 446 | #ifndef USE_PTHREAD |
447 | this->thread = (HANDLE)_beginthreadex(NULL, 0, llthread_child_thread_run, child, 0, NULL); | 447 | this->thread = (HANDLE)_beginthreadex(NULL, 0, llthread_child_thread_run, child, 0, NULL); |
448 | if(INVALID_THREAD == this->thread){ | 448 | if(INVALID_THREAD == this->thread){ |
449 | rc = -1 | 449 | rc = -1; |
450 | } | 450 | } |
451 | #else | 451 | #else |
452 | rc = pthread_create(&(this->thread), NULL, llthread_child_thread_run, child); | 452 | rc = pthread_create(&(this->thread), NULL, llthread_child_thread_run, child); |