diff options
| -rw-r--r-- | src/llthread.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/llthread.c b/src/llthread.c index ffb8235..492766e 100644 --- a/src/llthread.c +++ b/src/llthread.c | |||
| @@ -339,13 +339,15 @@ void llthread_log(lua_State *L, const char *hdr, const char *msg){ | |||
| 339 | static void open_thread_libs(lua_State *L){ | 339 | static void open_thread_libs(lua_State *L){ |
| 340 | int top = lua_gettop(L); | 340 | int top = lua_gettop(L); |
| 341 | 341 | ||
| 342 | /* luaL_openlibs(L); lua_settop(L, top); return; */ | 342 | #ifndef LLTHREAD_REGISTER_STD_LIBRARY |
| 343 | 343 | luaL_openlibs(L); | |
| 344 | #ifdef LLTHREAD_REGISTER_STD_LIBRARY | 344 | lua_getglobal(L, "package"); lua_getfield(L, -1, "preload"); lua_remove(L, -2); |
| 345 | # define L_REGLIB(L, name, G) lua_pushcfunction(L, luaopen_##name); lua_setfield(L, -2, #name) | 345 | lua_pushcfunction(L, luaopen_llthreads); lua_setfield(L, -2, "llthreads"); |
| 346 | lua_settop(L, top); | ||
| 347 | return; | ||
| 346 | #else | 348 | #else |
| 347 | # define L_REGLIB(L, name, G) lutil_require(L, #name, luaopen_##name, G) | 349 | |
| 348 | #endif | 350 | #define L_REGLIB(L, name, G) lua_pushcfunction(L, luaopen_##name); lua_setfield(L, -2, #name) |
| 349 | 351 | ||
| 350 | lutil_require(L, "_G", luaopen_base, 1); | 352 | lutil_require(L, "_G", luaopen_base, 1); |
| 351 | lutil_require(L, "package", luaopen_package, 1); | 353 | lutil_require(L, "package", luaopen_package, 1); |
| @@ -353,20 +355,18 @@ static void open_thread_libs(lua_State *L){ | |||
| 353 | 355 | ||
| 354 | /* get package.preload */ | 356 | /* get package.preload */ |
| 355 | lua_getglobal(L, "package"); lua_getfield(L, -1, "preload"); lua_remove(L, -2); | 357 | lua_getglobal(L, "package"); lua_getfield(L, -1, "preload"); lua_remove(L, -2); |
| 356 | |||
| 357 | /*always only register*/ | ||
| 358 | lua_pushcfunction(L, luaopen_llthreads); lua_setfield(L, -2, "llthreads"); | ||
| 359 | |||
| 360 | L_REGLIB(L, io, 1); | 358 | L_REGLIB(L, io, 1); |
| 361 | L_REGLIB(L, os, 1); | 359 | L_REGLIB(L, os, 1); |
| 362 | L_REGLIB(L, math, 1); | 360 | L_REGLIB(L, math, 1); |
| 363 | L_REGLIB(L, table, 1); | 361 | L_REGLIB(L, table, 1); |
| 364 | L_REGLIB(L, string, 1); | 362 | L_REGLIB(L, string, 1); |
| 363 | L_REGLIB(L, llthreads, 0); | ||
| 365 | 364 | ||
| 366 | #ifdef LUA_DBLIBNAME | 365 | #ifdef LUA_DBLIBNAME |
| 367 | L_REGLIB(L, debug, 1); | 366 | L_REGLIB(L, debug, 1); |
| 368 | #endif | 367 | #endif |
| 369 | 368 | ||
| 369 | /* @fixme find out luaopen_XXX in runtime */ | ||
| 370 | #ifdef LUA_JITLIBNAME | 370 | #ifdef LUA_JITLIBNAME |
| 371 | L_REGLIB(L, bit, 1); | 371 | L_REGLIB(L, bit, 1); |
| 372 | L_REGLIB(L, jit, 1); | 372 | L_REGLIB(L, jit, 1); |
| @@ -377,6 +377,8 @@ static void open_thread_libs(lua_State *L){ | |||
| 377 | 377 | ||
| 378 | lua_settop(L, top); | 378 | lua_settop(L, top); |
| 379 | #undef L_REGLIB | 379 | #undef L_REGLIB |
| 380 | |||
| 381 | #endif | ||
| 380 | } | 382 | } |
| 381 | 383 | ||
| 382 | static llthread_child_t *llthread_child_new() { | 384 | static llthread_child_t *llthread_child_new() { |
