[vlc-commits] commit: LUA: store p_intf->p_sys separately ( Rémi Denis-Courmont )

git at videolan.org git at videolan.org
Sun Apr 11 13:57:25 CEST 2010


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Apr 11 14:56:12 2010 +0300| [30aaaa4a200013a270ce89beadd88bc31a3bb4b8] | committer: Rémi Denis-Courmont 

LUA: store p_intf->p_sys separately

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

 modules/misc/lua/intf.c      |    1 +
 modules/misc/lua/libs/misc.c |   36 ++++++++++++++++++++++++++++--------
 modules/misc/lua/vlc.h       |    3 +++
 3 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/modules/misc/lua/intf.c b/modules/misc/lua/intf.c
index 2687e54..1ceca46 100644
--- a/modules/misc/lua/intf.c
+++ b/modules/misc/lua/intf.c
@@ -171,6 +171,7 @@ int Open_LuaIntf( vlc_object_t *p_this )
     }
 
     vlclua_set_this( L, p_intf );
+    vlclua_set_intf( L, p_sys );
 
     luaL_openlibs( L );
 
diff --git a/modules/misc/lua/libs/misc.c b/modules/misc/lua/libs/misc.c
index 3b1fbae..54bac3d 100644
--- a/modules/misc/lua/libs/misc.c
+++ b/modules/misc/lua/libs/misc.c
@@ -47,24 +47,44 @@
 #include "../vlc.h"
 #include "../libs.h"
 
-#undef vlclua_set_this
 /*****************************************************************************
  * Internal lua<->vlc utils
  *****************************************************************************/
-void vlclua_set_this( lua_State *L, vlc_object_t *p_this )
+static void vlclua_set_object( lua_State *L, void *id, void *value )
 {
-    lua_pushlightuserdata( L, vlclua_set_this );
-    lua_pushlightuserdata( L, p_this );
+    lua_pushlightuserdata( L, id );
+    lua_pushlightuserdata( L, value );
     lua_rawset( L, LUA_REGISTRYINDEX );
 }
 
-vlc_object_t * vlclua_get_this( lua_State *L )
+static void *vlclua_get_object( lua_State *L, void *id )
 {
-    lua_pushlightuserdata( L, vlclua_set_this );
+    lua_pushlightuserdata( L, id );
     lua_rawget( L, LUA_REGISTRYINDEX );
-    vlc_object_t *p_this = (vlc_object_t*)lua_topointer( L, -1 );
+    const void *p = lua_topointer( L, -1 );
     lua_pop( L, 1 );
-    return p_this;
+    return (void *)p;
+}
+
+#undef vlclua_set_this
+void vlclua_set_this( lua_State *L, vlc_object_t *p_this )
+{
+    vlclua_set_object( L, vlclua_set_this, p_this );
+}
+
+vlc_object_t * vlclua_get_this( lua_State *L )
+{
+    return vlclua_get_object( L, vlclua_set_this );
+}
+
+void vlclua_set_intf( lua_State *L, intf_sys_t *p_intf )
+{
+    vlclua_set_object( L, vlclua_set_intf, p_intf );
+}
+
+static intf_sys_t * vlclua_get_intf( lua_State *L )
+{
+    return vlclua_get_object( L, vlclua_set_intf );
 }
 
 /*****************************************************************************
diff --git a/modules/misc/lua/vlc.h b/modules/misc/lua/vlc.h
index 0669c2d..71dfcc7 100644
--- a/modules/misc/lua/vlc.h
+++ b/modules/misc/lua/vlc.h
@@ -95,6 +95,9 @@ void vlclua_set_this( lua_State *, vlc_object_t * );
 #define vlclua_set_this(a, b) vlclua_set_this(a, VLC_OBJECT(b))
 vlc_object_t * vlclua_get_this( lua_State * );
 
+struct intf_sys_t;
+void vlclua_set_intf( lua_State *, struct intf_sys_t * );
+
 /*****************************************************************************
  * Lua function bridge
  *****************************************************************************/



More information about the vlc-commits mailing list