]> git.sesse.net Git - vlc/blobdiff - modules/misc/lua/vlc.c
Add --data-path option. Access the src share directory now works from build tree.
[vlc] / modules / misc / lua / vlc.c
index 32cc2ab35907cc20815ffddab79588e9e80319c7..f26638eb65f0e34ba0dd88850cb1b437b777bac5 100644 (file)
 #define CONFIG_TEXT N_("Lua interface configuration")
 #define CONFIG_LONGTEXT N_("Lua interface configuration string. Format is: '[\"<interface module name>\"] = { <option> = <value>, ...}, ...'.")
 
-vlc_module_begin();
-        set_shortname( N_( "Lua Art" ) );
-        set_description( N_("Fetch artwork using lua scripts") );
-        set_capability( "art finder", 10 );
-        set_callbacks( FindArt, NULL );
-
-    add_submodule();
-        add_shortcut( "luaplaylist" );
-        set_category( CAT_INPUT );
-        set_subcategory( SUBCAT_INPUT_DEMUX );
-        set_shortname( N_("Lua Playlist") );
-        set_description( N_("Lua Playlist Parser Interface") );
-        set_capability( "demux", 2 );
-        set_callbacks( Import_LuaPlaylist, Close_LuaPlaylist );
-
-    add_submodule();
-        add_shortcut( "luaintf" );
-        add_shortcut( "luarc" );
-        /* add_shortcut( "rc" ); */
-        add_shortcut( "luahotkeys" );
-        /* add_shortcut( "hotkeys" ); */
-        add_shortcut( "luatelnet" );
-        /* add_shortcut( "telnet" ); */
-        add_shortcut( "luahttp" );
-        /* add_shortcut( "http" ); */
-        set_description( N_("Lua Interface Module") );
-        set_capability( "interface", 0 );
+vlc_module_begin ()
+        set_shortname( N_( "Lua Art" ) )
+        set_description( N_("Fetch artwork using lua scripts") )
+        set_capability( "art finder", 10 )
+        set_callbacks( FindArt, NULL )
+
+    add_submodule ()
+        add_shortcut( "luaplaylist" )
+        set_category( CAT_INPUT )
+        set_subcategory( SUBCAT_INPUT_DEMUX )
+        set_shortname( N_("Lua Playlist") )
+        set_description( N_("Lua Playlist Parser Interface") )
+        set_capability( "demux", 2 )
+        set_callbacks( Import_LuaPlaylist, Close_LuaPlaylist )
+
+    add_submodule ()
+        add_shortcut( "luaintf" )
+        add_shortcut( "luarc" )
+        /* add_shortcut( "rc" ) */
+        add_shortcut( "luahotkeys" )
+        /* add_shortcut( "hotkeys" ) */
+        add_shortcut( "luatelnet" )
+        /* add_shortcut( "telnet" ) */
+        add_shortcut( "luahttp" )
+        /* add_shortcut( "http" ) */
+        set_description( N_("Lua Interface Module") )
+        set_capability( "interface", 0 )
         add_string( "lua-intf", "dummy", NULL,
-                    INTF_TEXT, INTF_LONGTEXT, false );
+                    INTF_TEXT, INTF_LONGTEXT, false )
         add_string( "lua-config", "", NULL,
-                    CONFIG_TEXT, CONFIG_LONGTEXT, false );
-        set_callbacks( Open_LuaIntf, Close_LuaIntf );
-vlc_module_end();
+                    CONFIG_TEXT, CONFIG_LONGTEXT, false )
+        set_callbacks( Open_LuaIntf, Close_LuaIntf )
+vlc_module_end ()
 
 /*****************************************************************************
  *
@@ -105,10 +105,10 @@ static int file_compare( const char **a, const char **b )
     return strcmp( *a, *b );
 }
 
-int vlclua_dir_list( const char *luadirname, char **ppsz_dir_list )
+int vlclua_dir_list( vlc_object_t *p_this, const char *luadirname, char **ppsz_dir_list )
 {
     int i = 0;
-    char *datadir = config_GetUserDataDir();
+    char *datadir = config_GetUserDir( VLC_DATA_DIR );
     if( datadir == NULL )
         return VLC_ENOMEM;
 
@@ -121,42 +121,36 @@ int vlclua_dir_list( const char *luadirname, char **ppsz_dir_list )
     free( datadir );
     i++;
 
+    char *psz_datapath = config_GetDataDir( p_this );
 #   if defined(__APPLE__) || defined(SYS_BEOS) || defined(WIN32)
     {
-        const char *psz_vlcpath = config_GetDataDir();
         if( asprintf( &ppsz_dir_list[i], "%s" DIR_SEP "lua" DIR_SEP "%s",
-                      psz_vlcpath, luadirname )  < 0 )
+                      psz_datapath, luadirname )  < 0 )
             return VLC_ENOMEM;
         i++;
         if( asprintf( &ppsz_dir_list[i], "%s" DIR_SEP "share" DIR_SEP "lua" DIR_SEP "%s",
-                      psz_vlcpath, luadirname )  < 0 )
+                      psz_datapath, luadirname )  < 0 )
             return VLC_ENOMEM;
         i++;
 
     }
 #   else
-    if( asprintf( &ppsz_dir_list[i],
-                  "share" DIR_SEP "lua" DIR_SEP "%s", luadirname ) < 0 )
+    if( asprintf( &ppsz_dir_list[i], "%s" DIR_SEP "lua" DIR_SEP "%s",
+                  psz_datapath, luadirname ) < 0 )
         return VLC_ENOMEM;
-
-#   ifdef HAVE_SYS_STAT_H
-    {
-        struct stat stat_info;
-        if( ( utf8_stat( ppsz_dir_list[i], &stat_info ) == -1 )
-            || !S_ISDIR( stat_info.st_mode ) )
-        {
-            free(ppsz_dir_list[i]);
-            if( asprintf( &ppsz_dir_list[i], "%s" DIR_SEP "lua" DIR_SEP "%s",
-                          config_GetDataDir (), luadirname ) < 0 )
-                return VLC_ENOMEM;
-        }
-    }
-#   endif
     i++;
 #   endif
+    free( psz_datapath );
     return VLC_SUCCESS;
 }
 
+void vlclua_dir_list_free( char **ppsz_dir_list )
+{
+    char **ppsz_dir;
+    for( ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )
+        free( *ppsz_dir );
+}
+
 /*****************************************************************************
  * Will execute func on all scripts in luadirname, and stop if func returns
  * success.
@@ -176,7 +170,7 @@ int vlclua_scripts_batch_execute( vlc_object_t *p_this,
     char  *ppsz_dir_list[] = { NULL, NULL, NULL, NULL };
     char **ppsz_dir;
 
-    i_ret = vlclua_dir_list( luadirname, ppsz_dir_list );
+    i_ret = vlclua_dir_list( p_this, luadirname, ppsz_dir_list );
     if( i_ret != VLC_SUCCESS )
         return i_ret;
     i_ret = VLC_EGENERIC;
@@ -206,7 +200,10 @@ int vlclua_scripts_batch_execute( vlc_object_t *p_this,
             char  *psz_filename;
             if( asprintf( &psz_filename,
                           "%s" DIR_SEP "%s", *ppsz_dir, *ppsz_file ) < 0)
+            {
+                vlclua_dir_list_free( ppsz_dir_list );
                 return VLC_ENOMEM;
+            }
             msg_Dbg( p_this, "Trying Lua playlist script %s", psz_filename );
 
             i_ret = func( p_this, psz_filename, L, user_data );
@@ -225,8 +222,7 @@ int vlclua_scripts_batch_execute( vlc_object_t *p_this,
             free( *ppsz_file );
         free( ppsz_filelist );
     }
-    for( ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )
-        free( *ppsz_dir );
+    vlclua_dir_list_free( ppsz_dir_list );
 
     return i_ret;
 }
@@ -321,8 +317,8 @@ void __vlclua_read_custom_meta_data( vlc_object_t *p_this, lua_State *L,
                         msg_Dbg( p_this, "Custom meta %s, %s: %s",
                                  psz_meta_category, psz_meta_name,
                                  psz_meta_value );
-                        input_ItemAddInfo( p_input, psz_meta_category,
-                                           psz_meta_name, psz_meta_value );
+                        input_item_AddInfo( p_input, psz_meta_category,
+                                           psz_meta_name, "%s", psz_meta_value );
                     }
                     lua_pop( L, 1 ); /* pop item */
                     /* ... item meta key value key2 */
@@ -438,9 +434,10 @@ int __vlclua_playlist_add_internal( vlc_object_t *p_this, lua_State *L,
                     vlclua_read_options( p_this, L, &i_options, &ppsz_options );
 
                     /* Create input item */
-                    p_input = input_ItemNewExt( p_playlist, psz_path,
+                    p_input = input_item_NewExt( p_playlist, psz_path,
                                                 psz_name, i_options,
                                                 (const char **)ppsz_options,
+                                                VLC_INPUT_OPTION_TRUSTED,
                                                 i_duration );
                     lua_pop( L, 3 ); /* pop "path name item" */
                     /* playlist key item */
@@ -453,7 +450,7 @@ int __vlclua_playlist_add_internal( vlc_object_t *p_this, lua_State *L,
 
                     /* Append item to playlist */
                     if( p_parent ) /* Add to node */
-                        input_ItemAddSubItem( p_parent, p_input );
+                        input_item_AddSubItem( p_parent, p_input );
                     else /* Play or Enqueue (preparse) */
                         /* FIXME: playlist_AddInput() can fail */
                         playlist_AddInput( p_playlist, p_input,