diff options
author | Arvydas Sidorenko <asido4@gmail.com> | 2012-07-03 11:32:20 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2012-07-03 11:32:20 +0200 |
commit | 69fde9c427bf604cdc4d6c4c38004eda62ef8ccc (patch) | |
tree | 7fa13f3166a742759f30ddbfd2e8e32293a899d4 /src/plugins/scripts/lua | |
parent | e84099fb97d33fd80986be123cf85ca47d88ddef (diff) | |
download | weechat-69fde9c427bf604cdc4d6c4c38004eda62ef8ccc.zip |
lua: remove call to deprecated function luaL_openlib (compatibility with Lua 5.2)
Signed-off-by: Arvydas Sidorenko <asido4@gmail.com>
Diffstat (limited to 'src/plugins/scripts/lua')
-rw-r--r-- | src/plugins/scripts/lua/weechat-lua.c | 24 | ||||
-rw-r--r-- | src/plugins/scripts/lua/weechat-lua.h | 2 |
2 files changed, 25 insertions, 1 deletions
diff --git a/src/plugins/scripts/lua/weechat-lua.c b/src/plugins/scripts/lua/weechat-lua.c index 2cfea5f5e..6ab5ce33f 100644 --- a/src/plugins/scripts/lua/weechat-lua.c +++ b/src/plugins/scripts/lua/weechat-lua.c @@ -226,6 +226,28 @@ weechat_lua_exec (struct t_plugin_script *script, int ret_type, } /* + * 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) diff --git a/src/plugins/scripts/lua/weechat-lua.h b/src/plugins/scripts/lua/weechat-lua.h index 944a2acbd..0512d2272 100644 --- a/src/plugins/scripts/lua/weechat-lua.h +++ b/src/plugins/scripts/lua/weechat-lua.h @@ -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 */ |