]> git.sesse.net Git - vlc/blobdiff - modules/misc/lua/meta.c
lua_meta: factorize.
[vlc] / modules / misc / lua / meta.c
index b61ec4ec6af84ea2cd054d00c6b5ff347f94e1c9..650fb0d98db1dd76651624949dc987346f1834cd 100644 (file)
@@ -35,7 +35,6 @@
 
 #include <vlc_common.h>
 #include <vlc_input.h>
-#include <vlc_playlist.h>
 #include <vlc_meta.h>
 #include <vlc_demux.h>
 #include <vlc_art_finder.h>
@@ -60,6 +59,8 @@ static lua_State * init( vlc_object_t *p_this, input_item_t * p_item, const char
         return NULL;
     }
 
+    vlclua_set_this( L, p_this );
+
     /* Load Lua libraries */
     luaL_openlibs( L ); /* XXX: Don't open all the libs? */
 
@@ -75,9 +76,6 @@ static lua_State * init( vlc_object_t *p_this, input_item_t * p_item, const char
     luaopen_md5( L );
     luaopen_input_item( L, p_item );
 
-    lua_pushlightuserdata( L, p_this );
-    lua_setfield( L, -2, "private" );
-
     if( vlclua_add_modules_path( p_this, L, psz_filename ) )
     {
         msg_Warn( p_this, "Error while setting the module search path for %s",
@@ -112,14 +110,14 @@ static int run( vlc_object_t *p_this, const char * psz_filename,
 
     if( !lua_isfunction( L, lua_gettop( L ) ) )
     {
-        msg_Warn( p_this, "Error while runing script %s, "
+        msg_Warn( p_this, "Error while running script %s, "
                  "function %s() not found", psz_filename, luafunction );
         goto error;
     }
 
     if( lua_pcall( L, 0, 1, 0 ) )
     {
-        msg_Warn( p_this, "Error while runing script %s, "
+        msg_Warn( p_this, "Error while running script %s, "
                  "function %s(): %s", psz_filename, luafunction,
                  lua_tostring( L, lua_gettop( L ) ) );
         goto error;
@@ -139,7 +137,6 @@ static int fetch_art( vlc_object_t *p_this, const char * psz_filename,
                       void * user_data )
 {
     input_item_t * p_item = user_data;
-    int s;
 
     lua_State *L = init( p_this, p_item, psz_filename );
     if( !L )
@@ -152,13 +149,13 @@ static int fetch_art( vlc_object_t *p_this, const char * psz_filename,
         return i_ret;
     }
 
-    if((s = lua_gettop( L )))
+    if(lua_gettop( L ))
     {
         const char * psz_value;
 
-        if( lua_isstring( L, s ) )
+        if( lua_isstring( L, -1 ) )
         {
-            psz_value = lua_tostring( L, s );
+            psz_value = lua_tostring( L, -1 );
             if( psz_value && *psz_value != 0 )
             {
                 lua_Dbg( p_this, "setting arturl: %s", psz_value );
@@ -167,7 +164,7 @@ static int fetch_art( vlc_object_t *p_this, const char * psz_filename,
                 return VLC_SUCCESS;
             }
         }
-        else if( !lua_isnil( L, s ) )
+        else if( !lua_isnoneornil( L, -1 ) )
         {
             msg_Err( p_this, "Lua art fetcher script %s: "
                  "didn't return a string", psz_filename );
@@ -183,7 +180,7 @@ static int fetch_art( vlc_object_t *p_this, const char * psz_filename,
 }
 
 /*****************************************************************************
- * Called through lua_scripts_batch_execute to call 'fetch_art' on the script
+ * Called through lua_scripts_batch_execute to call 'read_meta' on the script
  * pointed by psz_filename.
  *****************************************************************************/
 static int read_meta( vlc_object_t *p_this, const char * psz_filename,
@@ -195,15 +192,10 @@ static int read_meta( vlc_object_t *p_this, const char * psz_filename,
         return VLC_EGENERIC;
 
     int i_ret = run(p_this, psz_filename, L, "read_meta");
-    if(i_ret != VLC_SUCCESS)
-    {
-        lua_close( L );
-        return i_ret;
-    }
-
-    // Continue, all "meta reader" are always run.
     lua_close( L );
-    return 1;
+
+    // Continue even if an error occured: all "meta reader" are always run.
+    return i_ret == VLC_SUCCESS ? VLC_EGENERIC : i_ret;
 }