weechat-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Weechat-dev] [PATCH 3/3] Replaced already in Lua 5.1 deprecated luaL_op


From: Arvydas Sidorenko
Subject: [Weechat-dev] [PATCH 3/3] Replaced already in Lua 5.1 deprecated luaL_openlib
Date: Tue, 26 Jun 2012 02:00:49 +0200

Signed-off-by: Arvydas Sidorenko <address@hidden>
---
 src/plugins/scripts/lua/weechat-lua.c |   24 +++++++++++++++++++++++-
 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 2cfea5f..b316cc3 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_registerlib: registers a library to use inside Lua script
+ */
+
+void weechat_lua_registerlib(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_registerlib (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 944a2ac..b54526b 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_registerlib(lua_State *L, const char *libname,
+                                    const luaL_Reg *l);
 
 #endif /* __WEECHAT_LUA_H */
-- 
1.7.8.6




reply via email to

[Prev in Thread] Current Thread [Next in Thread]