[vlc-commits] LUA: simplify pushing VLC object

Rémi Denis-Courmont git at videolan.org
Tue Jul 19 22:32:24 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Jul 19 23:31:26 2011 +0300| [7510a32ec261429e758eef4d1eba5740dd3bc49f] | committer: Rémi Denis-Courmont

LUA: simplify pushing VLC object

Always use the common GC wrapper around vlc_object_release(). While it
is not really required for the instance and the playlist object, the
overhead is negligible in LUA context.

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

 modules/lua/libs/objects.c |   24 +++++++++++-------------
 modules/lua/libs/objects.h |    8 +++-----
 2 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/modules/lua/libs/objects.c b/modules/lua/libs/objects.c
index 5c4d49f..ab795d8 100644
--- a/modules/lua/libs/objects.c
+++ b/modules/lua/libs/objects.c
@@ -46,7 +46,7 @@
 /*****************************************************************************
  * Generic vlc_object_t wrapper creation
  *****************************************************************************/
-int vlclua_gc_release( lua_State *L )
+static int vlclua_object_release( lua_State *L )
 {
     vlc_object_t **p_obj = (vlc_object_t **)luaL_checkudata( L, 1, "vlc_object" );
     lua_pop( L, 1 );
@@ -62,8 +62,9 @@ static int vlclua_object_find( lua_State *L )
 
 static int vlclua_get_libvlc( lua_State *L )
 {
-    vlclua_push_vlc_object( L, vlclua_get_this( L )->p_libvlc,
-                            NULL );
+    libvlc_int_t *p_libvlc = vlclua_get_this( L )->p_libvlc;
+    vlc_object_hold( p_libvlc );
+    vlclua_push_vlc_object( L, p_libvlc );
     return 1;
 }
 
@@ -72,8 +73,8 @@ static int vlclua_get_playlist( lua_State *L )
     playlist_t *p_playlist = vlclua_get_playlist_internal( L );
     if( p_playlist )
     {
-        vlclua_push_vlc_object( L, p_playlist, vlclua_gc_release );
         vlc_object_hold( p_playlist );
+        vlclua_push_vlc_object( L, p_playlist );
     }
     else lua_pushnil( L );
     return 1;
@@ -84,15 +85,15 @@ static int vlclua_get_input( lua_State *L )
     input_thread_t *p_input = vlclua_get_input_internal( L );
     if( p_input )
     {
-        vlclua_push_vlc_object( L, p_input, vlclua_gc_release );
+        /* NOTE: p_input is already held by vlclua_get_input_internal() */
+        vlclua_push_vlc_object( L, p_input );
     }
     else lua_pushnil( L );
     return 1;
 }
 
 #undef vlclua_push_vlc_object
-int vlclua_push_vlc_object( lua_State *L, vlc_object_t *p_obj,
-                              lua_CFunction pf_gc )
+int vlclua_push_vlc_object( lua_State *L, vlc_object_t *p_obj )
 {
     vlc_object_t **udata = (vlc_object_t **)
         lua_newuserdata( L, sizeof( vlc_object_t * ) );
@@ -103,12 +104,9 @@ int vlclua_push_vlc_object( lua_State *L, vlc_object_t *p_obj,
         /* Hide the metatable */
         lua_pushliteral( L, "none of your business" );
         lua_setfield( L, -2, "__metatable" );
-        if( pf_gc ) /* FIXME */
-        {
-            /* Set the garbage collector if needed */
-            lua_pushcfunction( L, pf_gc );
-            lua_setfield( L, -2, "__gc" );
-        }
+        /* Set the garbage collector if needed */
+        lua_pushcfunction( L, vlclua_object_release );
+        lua_setfield( L, -2, "__gc" );
     }
     lua_setmetatable( L, -2 );
     return 1;
diff --git a/modules/lua/libs/objects.h b/modules/lua/libs/objects.h
index 687a1d5..e978e7c 100644
--- a/modules/lua/libs/objects.h
+++ b/modules/lua/libs/objects.h
@@ -25,11 +25,9 @@
 #ifndef VLC_LUA_OBJECTS_H
 #define VLC_LUA_OBJECTS_H
 
-int vlclua_push_vlc_object( lua_State *L, vlc_object_t *p_obj,
-                              lua_CFunction pf_gc );
-#define vlclua_push_vlc_object( a, b, c ) \
-        vlclua_push_vlc_object( a, VLC_OBJECT( b ), c )
-int vlclua_gc_release( lua_State *L );
+int vlclua_push_vlc_object( lua_State *L, vlc_object_t *p_obj );
+#define vlclua_push_vlc_object( a, b ) \
+        vlclua_push_vlc_object( a, VLC_OBJECT( b ) )
 
 #endif
 



More information about the vlc-commits mailing list