aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormoteus <mimir@newmail.ru>2013-12-26 13:08:45 +0400
committermoteus <mimir@newmail.ru>2013-12-26 13:08:45 +0400
commit7b90a331bf1caecfa1ba1e2f3e7f87fa01c389b9 (patch)
treebdf13cff8a9eda9eb8c90b763f41cb06ea08942a /src
parent1ddc9bd2a0e5f9f4835e39c05df0850cb9aa44bf (diff)
downloadlua-llthreads2-7b90a331bf1caecfa1ba1e2f3e7f87fa01c389b9.tar.gz
lua-llthreads2-7b90a331bf1caecfa1ba1e2f3e7f87fa01c389b9.tar.bz2
lua-llthreads2-7b90a331bf1caecfa1ba1e2f3e7f87fa01c389b9.zip
Fix. load library on Lua 5.2
Diffstat (limited to 'src')
-rw-r--r--src/l52util.c5
-rw-r--r--src/l52util.h5
-rw-r--r--src/llthread.c24
3 files changed, 22 insertions, 12 deletions
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
46void 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
48int lutil_newmetatablep (lua_State *L, const void *p) { 53int 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
19void luaL_register (lua_State *L, const char *libname, const luaL_Reg *l); 19void 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);
29void lua_rawsetp (lua_State *L, int index, const void *p); 32void lua_rawsetp (lua_State *L, int index, const void *p);
30void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup); 33void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup);
31 34
35void lutil_require(lua_State *L, const char* name, lua_CFunction fn, int glb);
36
32#endif 37#endif
33 38
34int lutil_newmetatablep (lua_State *L, const void *p); 39int 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
309static void open_thread_libs(lua_State *L){ 309static 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);