[vlc-commits] lua: 'vlc' namespace needs to be handled differently

Ludovic Fauvet git at videolan.org
Wed Mar 16 18:33:36 CET 2016


vlc | branch: master | Ludovic Fauvet <etix at videolan.org> | Wed Mar 16 18:26:07 2016 +0100| [42e55422e9ab25b7f5d52e72279f441b3860b142] | committer: Ludovic Fauvet

lua: 'vlc' namespace needs to be handled differently

But apparently this is not enough, some lua plugins are still broken.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=42e55422e9ab25b7f5d52e72279f441b3860b142
---

 modules/lua/demux.c              |    4 ++--
 modules/lua/extension.c          |    2 +-
 modules/lua/intf.c               |    2 +-
 modules/lua/meta.c               |    2 +-
 modules/lua/services_discovery.c |    2 +-
 modules/lua/vlc.h                |    7 +++++++
 6 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/modules/lua/demux.c b/modules/lua/demux.c
index b815a11..5575685 100644
--- a/modules/lua/demux.c
+++ b/modules/lua/demux.c
@@ -141,7 +141,7 @@ static int probe_luascript( vlc_object_t *p_this, const char * psz_filename,
     luaL_openlibs( L ); /* FIXME: Don't open all the libs? */
 
     vlclua_set_this( L, p_demux );
-    luaL_register( L, "vlc", p_reg );
+    luaL_register_namespace( L, "vlc", p_reg );
     luaopen_msg( L );
     luaopen_strings( L );
     luaopen_stream( L );
@@ -248,7 +248,7 @@ static int Demux( demux_t *p_demux )
 
     input_item_t *p_current_input = input_GetItem( p_demux->p_input );
 
-    luaL_register( L, "vlc", p_reg_parse );
+    luaL_register_namespace( L, "vlc", p_reg_parse );
 
     lua_getglobal( L, "parse" );
 
diff --git a/modules/lua/extension.c b/modules/lua/extension.c
index 30f1040..f3c60af 100644
--- a/modules/lua/extension.c
+++ b/modules/lua/extension.c
@@ -816,7 +816,7 @@ static lua_State* GetLuaState( extensions_manager_t *p_mgr,
         vlclua_extension_set( L, p_ext );
 
         luaL_openlibs( L );
-        luaL_register( L, "vlc", p_reg );
+        luaL_register_namespace( L, "vlc", p_reg );
         luaopen_msg( L );
 
         if( p_ext )
diff --git a/modules/lua/intf.c b/modules/lua/intf.c
index 3fc48f9..1e43a8e 100644
--- a/modules/lua/intf.c
+++ b/modules/lua/intf.c
@@ -245,7 +245,7 @@ static int Start_LuaIntf( vlc_object_t *p_this, const char *name )
     luaL_openlibs( L );
 
     /* register our functions */
-    luaL_register( L, "vlc", p_reg );
+    luaL_register_namespace( L, "vlc", p_reg );
 
     /* register submodules */
     luaopen_config( L );
diff --git a/modules/lua/meta.c b/modules/lua/meta.c
index b78fa93..2dfba88 100644
--- a/modules/lua/meta.c
+++ b/modules/lua/meta.c
@@ -55,7 +55,7 @@ static lua_State * init( vlc_object_t *p_this, input_item_t * p_item, const char
     /* Load Lua libraries */
     luaL_openlibs( L ); /* XXX: Don't open all the libs? */
 
-    luaL_register( L, "vlc", p_reg );
+    luaL_register_namespace( L, "vlc", p_reg );
 
     luaopen_msg( L );
     luaopen_stream( L );
diff --git a/modules/lua/services_discovery.c b/modules/lua/services_discovery.c
index b18b3d5..3efb09e 100644
--- a/modules/lua/services_discovery.c
+++ b/modules/lua/services_discovery.c
@@ -107,7 +107,7 @@ int Open_LuaSD( vlc_object_t *p_this )
     }
     vlclua_set_this( L, p_sd );
     luaL_openlibs( L );
-    luaL_register( L, "vlc", p_reg );
+    luaL_register_namespace( L, "vlc", p_reg );
     luaopen_input( L );
     luaopen_msg( L );
     luaopen_object( L );
diff --git a/modules/lua/vlc.h b/modules/lua/vlc.h
index 1fa78fd..4a7a7d3 100644
--- a/modules/lua/vlc.h
+++ b/modules/lua/vlc.h
@@ -53,6 +53,13 @@
 #if LUA_VERSION_NUM >= 503
 # undef luaL_register
 # define luaL_register(L, n, l) luaL_setfuncs(L, (l), 0)
+# define luaL_register_namespace(L, n, l) \
+    lua_newtable( L ); \
+    luaL_setfuncs( L, (l), 0 ); \
+    lua_pushvalue( L, -1 ); \
+    lua_setglobal( L, n );
+#else
+# define luaL_register_namespace(L, n, l) luaL_register( L, n, (l) );
 #endif
 
 



More information about the vlc-commits mailing list