diff options
Diffstat (limited to 'src/anylike.c')
-rw-r--r-- | src/anylike.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/anylike.c b/src/anylike.c index bc3bc7a..b509a5e 100644 --- a/src/anylike.c +++ b/src/anylike.c @@ -97,6 +97,19 @@ extern const uint32_t anylike_lua_bytecode_len; #define LUA_MAIN_LOOP_FUNC "main_loop" +#if LUA_VERSION_NUM > 501 +static const luaL_Reg anylike_lualibs[] = { + {"_G", luaopen_base}, + {LUA_LOADLIBNAME, luaopen_package}, + {LUA_TABLIBNAME, luaopen_table}, + {LUA_STRLIBNAME, luaopen_string}, + {LUA_MATHLIBNAME, luaopen_math}, + {LUA_LOGLIBNAME, luaopen_log}, + {LUA_SIGNALLIBNAME, luaopen_signal}, + {LUA_CRYPTLIBNAME, luaopen_crypt}, + {NULL, NULL} +}; +#else static const luaL_Reg anylike_lualibs[] = { {"", luaopen_base}, {LUA_LOADLIBNAME, luaopen_package}, @@ -108,15 +121,24 @@ static const luaL_Reg anylike_lualibs[] = { {LUA_CRYPTLIBNAME, luaopen_crypt}, {NULL, NULL} }; +#endif int init_main_loop(lua_State *L) { const luaL_Reg *lib = anylike_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, anylike_lua_bytecode, anylike_lua_bytecode_len, "anylike"); if(ret) { |