diff options
Diffstat (limited to 'src/luaclient.c')
-rw-r--r-- | src/luaclient.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/luaclient.c b/src/luaclient.c index 7ac102d..104de52 100644 --- a/src/luaclient.c +++ b/src/luaclient.c @@ -43,7 +43,23 @@ #define LUA_MAIN_LOOP_FUNC "main_loop" -static const luaL_Reg anylike_lualibs[] = { +#if LUA_VERSION_NUM > 501 +static const luaL_Reg luaclient_lualibs[] = { + {"_G", luaopen_base}, + {LUA_LOADLIBNAME, luaopen_package}, + {LUA_TABLIBNAME, luaopen_table}, + {LUA_STRLIBNAME, luaopen_string}, + {LUA_MATHLIBNAME, luaopen_math}, + {LUA_IOLIBNAME, luaopen_io}, + {LUA_OSLIBNAME, luaopen_os}, + {LUA_BITLIBNAME, luaopen_bit32}, + {LUA_LOGLIBNAME, luaopen_log}, + {LUA_SIGNALLIBNAME, luaopen_signal}, + {LUA_CMDLIBNAME, luaopen_cmd}, + {NULL, NULL} +}; +#else +static const luaL_Reg luaclient_lualibs[] = { {"", luaopen_base}, {LUA_LOADLIBNAME, luaopen_package}, {LUA_TABLIBNAME, luaopen_table}, @@ -56,15 +72,24 @@ static const luaL_Reg anylike_lualibs[] = { {LUA_CMDLIBNAME, luaopen_cmd}, {NULL, NULL} }; +#endif int init_main_loop(lua_State *L, const char* filename) { - const luaL_Reg *lib = anylike_lualibs; + const luaL_Reg *lib = luaclient_lualibs; + +#if LUA_VERSION_NUM > 501 + for (; lib->func; lib++) { + luaL_requiref(L, lib->name, lib->func, 1); + lua_pop(L, 1); + } +#else for (; lib->func; lib++) { lua_pushcfunction(L, lib->func); lua_pushstring(L, lib->name); lua_call(L, 1, 0); } +#endif int ret = luaL_loadfile(L, filename); if(ret) { |