lua: remove call to deprecated function luaL_openlib (compatibility with Lua 5.2)

Signed-off-by: Arvydas Sidorenko <asido4@gmail.com>
This commit is contained in:
Arvydas Sidorenko 2012-07-03 11:32:20 +02:00 committed by Sebastien Helleu
parent e84099fb97
commit 69fde9c427
2 changed files with 25 additions and 1 deletions

View File

@ -225,6 +225,28 @@ weechat_lua_exec (struct t_plugin_script *script, int ret_type,
return ret_value;
}
/*
* weechat_lua_register_lib: register a library to use inside Lua script
*/
void weechat_lua_register_lib (lua_State *L, const char *libname,
const luaL_Reg *l)
{
#if LUA_VERSION_NUM >= 502
if (libname)
{
lua_newtable (L);
luaL_setfuncs (L, l, 0);
lua_pushvalue (L, -1);
lua_setglobal (L, libname);
}
else
luaL_setfuncs (L, l, 0);
#else
luaL_register (L, libname, l);
#endif
}
/*
* weechat_lua_load: load a Lua script
*/
@ -284,7 +306,7 @@ weechat_lua_load (const char *filename)
luaopen_debug (lua_current_interpreter);
#endif
luaL_openlib (lua_current_interpreter, "weechat", weechat_lua_api_funcs, 0);
weechat_lua_register_lib (lua_current_interpreter, "weechat", weechat_lua_api_funcs);
#ifdef LUA_VERSION_NUM
if (luaL_dostring (lua_current_interpreter, weechat_lua_code) != 0)

View File

@ -44,5 +44,7 @@ extern struct t_hashtable *weechat_lua_tohashtable (lua_State *interpreter,
extern void *weechat_lua_exec (struct t_plugin_script *script, int ret_type,
const char *function,
const char *format, void **argv);
extern void weechat_lua_register_lib(lua_State *L, const char *libname,
const luaL_Reg *l);
#endif /* __WEECHAT_LUA_H */