diff options
Diffstat (limited to 'src/gcsd.c')
-rw-r--r-- | src/gcsd.c | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -59,6 +59,22 @@ extern const size_t gcsd_lua_bytecode_len; #define LUA_MAIN_LOOP_FUNC "main_loop" +#if LUA_VERSION_NUM > 501 +static const luaL_Reg gcsd_lualibs[] = { + {"_G", luaopen_base}, + {LUA_LOADLIBNAME, luaopen_package}, + {LUA_TABLIBNAME, luaopen_table}, + {LUA_STRLIBNAME, luaopen_string}, + {LUA_MATHLIBNAME, luaopen_math}, + {LUA_RAWIOLIBNAME, luaopen_rawio}, + {LUA_TCPLIBNAME, luaopen_tcp}, + {LUA_UTILLIBNAME, luaopen_util}, + {LUA_TIMERLIBNAME, luaopen_timer}, + {LUA_LOGLIBNAME, luaopen_log}, + {LUA_SIGNALLIBNAME, luaopen_signal}, + {NULL, NULL} +}; +#else static const luaL_Reg gcsd_lualibs[] = { {"", luaopen_base}, {LUA_LOADLIBNAME, luaopen_package}, @@ -73,6 +89,7 @@ static const luaL_Reg gcsd_lualibs[] = { {LUA_SIGNALLIBNAME, luaopen_signal}, {NULL, NULL} }; +#endif int init_defines(lua_State *L) { @@ -118,11 +135,19 @@ int init_defines(lua_State *L) int init_main_loop(lua_State *L) { const luaL_Reg *lib = gcsd_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_loadbuffer(L, gcsd_lua_bytecode, gcsd_lua_bytecode_len, "gcsd"); if(ret) { |