[vlc-devel] commit: lua: Add the possibility to expose vlc.item. (Pierre d'Herbemont )

git version control git at videolan.org
Wed Jan 6 16:28:57 CET 2010


vlc | branch: master | Pierre d'Herbemont <pdherbemont at free.fr> | Wed Jan  6 16:06:35 2010 +0100| [1af19c857adc8bffa724dd9892aa7333fbb7cf96] | committer: Pierre d'Herbemont 

lua: Add the possibility to expose vlc.item.

Also support multiple meta data, and the "filename" meta data as well.

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

 modules/misc/lua/libs.h       |    1 +
 modules/misc/lua/libs/input.c |   49 ++++++++++++++++++++++++++++------------
 2 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/modules/misc/lua/libs.h b/modules/misc/lua/libs.h
index 7bd8701..da99a58 100644
--- a/modules/misc/lua/libs.h
+++ b/modules/misc/lua/libs.h
@@ -43,5 +43,6 @@ void luaopen_video( lua_State * );
 void luaopen_vlm( lua_State * );
 void luaopen_volume( lua_State * );
 void luaopen_gettext( lua_State * );
+void luaopen_input_item( lua_State *L, input_item_t *item );
 
 #endif
diff --git a/modules/misc/lua/libs/input.c b/modules/misc/lua/libs/input.c
index 68fbee2..105ae3c 100644
--- a/modules/misc/lua/libs/input.c
+++ b/modules/misc/lua/libs/input.c
@@ -119,6 +119,11 @@ static int vlclua_input_metas_internal( lua_State *L, input_item_t *p_item )
     lua_newtable( L );
     char *psz_meta;
 
+    psz_meta = input_item_GetName( p_item );
+    lua_pushstring( L, psz_meta );
+    lua_setfield( L, -2, "filename" );
+    free( psz_meta );
+    
 #define PUSH_META( n, m ) \
     psz_meta = input_item_GetMeta( p_item, vlc_meta_ ## n ); \
     lua_pushstring( L, psz_meta ); \
@@ -239,19 +244,9 @@ static int vlclua_input_item_delete( lua_State *L )
     return 1;
 }
 
-static int vlclua_input_item_get_current( lua_State *L )
+static int vlclua_input_item_get( lua_State *L, input_item_t *p_item )
 {
-    input_thread_t *p_input = vlclua_get_input_internal( L );
-    input_item_t *p_item = ( p_input && p_input->p ) ? input_GetItem( p_input ) : NULL;
-    if( !p_item )
-    {
-        lua_pushnil( L );
-        if( p_input ) vlc_object_release( p_input );
-        return 1;
-    }
-
     vlc_gc_incref( p_item );
-
     input_item_t **pp = lua_newuserdata( L, sizeof( void* ) );
     *pp = p_item;
 
@@ -264,7 +259,23 @@ static int vlclua_input_item_get_current( lua_State *L )
         lua_setfield( L, -2, "__gc" );
     }
 
-    lua_setmetatable( L, -2 );
+    lua_setmetatable(L, -2);
+    
+    return 1;
+}
+
+static int vlclua_input_item_get_current( lua_State *L )
+{
+    input_thread_t *p_input = vlclua_get_input_internal( L );
+    input_item_t *p_item = ( p_input && p_input->p ) ? input_GetItem( p_input ) : NULL;
+    if( !p_item )
+    {
+        lua_pushnil( L );
+        if( p_input ) vlc_object_release( p_input );
+        return 1;
+    }
+
+    vlclua_input_item_get( L, p_item );
 
     if( p_input ) vlc_object_release( p_input );
     return 1;
@@ -320,11 +331,12 @@ static int vlclua_input_item_set_meta( lua_State *L )
         }
     }
 
-    if( !ok )
-        return luaL_error( L, "unknown meta type '%s'", psz_name );
+    if( !ok ) {
+        vlc_meta_AddExtra( p_item->p_meta, psz_name, psz_value );
+        return 1;
+    }
 
     input_item_SetMeta( p_item, type, psz_value );
-
     return 1;
 }
 
@@ -354,3 +366,10 @@ static const luaL_Reg vlclua_input_item_reg[] = {
     { "set_meta", vlclua_input_item_set_meta },
     { NULL, NULL }
 };
+
+
+void luaopen_input_item( lua_State *L, input_item_t *item )
+{
+    vlclua_input_item_get( L, item );
+    lua_setfield( L, -2, "item" );
+}




More information about the vlc-devel mailing list