]> git.sesse.net Git - vlc/blobdiff - modules/misc/lua/vlc.c
Include vlc_plugin.h as needed
[vlc] / modules / misc / lua / vlc.c
index 634f21c8972ecc704029acacd298cb3d996978ae..20deb0c39b8f192125c16a6cf44f3fba3c067a15 100644 (file)
 #   define  _GNU_SOURCE
 #endif
 
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <vlc/vlc.h>
+#include <vlc_plugin.h>
 #include <vlc_meta.h>
 #include <vlc_charset.h>
 #include <vlc_aout.h>
 #define CONFIG_LONGTEXT N_("Lua interface configuration string. Format is: '[\"<interface module name>\"] = { <option> = <value>, ...}, ...'.")
 
 vlc_module_begin();
-    add_submodule();
-        add_shortcut( "luameta" );
-        set_shortname( N_( "Lua Meta" ) );
-        set_description( _("Fetch metadata using lua scripts") );
-        set_capability( "meta fetcher", 10 );
-        set_callbacks( E_(FindMeta), NULL );
     add_submodule();
         set_shortname( N_( "Lua Art" ) );
         set_description( _("Fetch artwork using lua scripts") );
@@ -68,7 +67,7 @@ vlc_module_begin();
         set_subcategory( SUBCAT_INPUT_DEMUX );
         set_shortname( _("Lua Playlist") );
         set_description( _("Lua Playlist Parser Interface") );
-        set_capability( "demux2", 9 );
+        set_capability( "demux", 2 );
         set_callbacks( E_(Import_LuaPlaylist), E_(Close_LuaPlaylist) );
     add_submodule();
         add_shortcut( "luaintf" );
@@ -83,9 +82,9 @@ vlc_module_begin();
         set_description( _("Lua Interface Module") );
         set_capability( "interface", 0 );
         add_string( "lua-intf", "dummy", NULL,
-                    INTF_TEXT, INTF_LONGTEXT, VLC_FALSE );
+                    INTF_TEXT, INTF_LONGTEXT, false );
         add_string( "lua-config", "", NULL,
-                    CONFIG_TEXT, CONFIG_LONGTEXT, VLC_FALSE );
+                    CONFIG_TEXT, CONFIG_LONGTEXT, false );
         set_callbacks( E_(Open_LuaIntf), E_(Close_LuaIntf) );
 vlc_module_end();
 
@@ -166,12 +165,16 @@ int vlclua_homedir( lua_State *L )
 }
 int vlclua_configdir( lua_State *L )
 {
-    lua_pushstring( L, vlclua_get_this( L )->p_libvlc->psz_configdir );
+    char *dir = config_GetUserConfDir();
+    lua_pushstring( L, dir );
+    free( dir );
     return 1;
 }
 int vlclua_cachedir( lua_State *L )
 {
-    lua_pushstring( L, vlclua_get_this( L )->p_libvlc->psz_cachedir );
+    char *dir = config_GetCacheDir();
+    lua_pushstring( L, dir );
+    free( dir );
     return 1;
 }
 int vlclua_datadir_list( lua_State *L )
@@ -256,7 +259,7 @@ int vlclua_stream_read( lua_State *L )
 {
     stream_t * p_stream;
     int n;
-    byte_t *p_read;
+    uint8_t *p_read;
     int i_read;
     p_stream = (stream_t *)luaL_checklightuserdata( L, 1 );
     n = luaL_checkint( L, 2 );
@@ -401,39 +404,59 @@ static int file_compare( const char **a, const char **b )
 int vlclua_dir_list( vlc_object_t *p_this, const char *luadirname,
                      char **ppsz_dir_list )
 {
-    if( asprintf( &ppsz_dir_list[0], "%s" DIR_SEP "%s",
-                   p_this->p_libvlc->psz_datadir, luadirname ) < 0 )
+    int i = 0;
+    char *datadir = config_GetUserDataDir();
+    if( datadir == NULL )
         return VLC_ENOMEM;
 
+    if( asprintf( &ppsz_dir_list[i], "%s" DIR_SEP "lua" DIR_SEP "%s",
+                   datadir, luadirname ) < 0 )
+    {
+        free( datadir );
+        return VLC_ENOMEM;
+    }
+    free( datadir );
+    i++;
+
 #   if defined(__APPLE__) || defined(SYS_BEOS) || defined(WIN32)
     {
         const char *psz_vlcpath = config_GetDataDir();
-        if( asprintf( &ppsz_dir_list[1], "%s" DIR_SEP "%s",
+        if( asprintf( &ppsz_dir_list[i], "%s" DIR_SEP "lua" DIR_SEP "%s",
                       psz_vlcpath, luadirname )  < 0 )
             return VLC_ENOMEM;
-
-        if( asprintf( &ppsz_dir_list[2], "%s" DIR_SEP "share" DIR_SEP "%s",
+        i++;
+#       ifdef WIN32
+        if( asprintf( &ppsz_dir_list[i], "%s" DIR_SEP "scripts" DIR_SEP "%s",
+                      psz_vlcpath, luadirname )  < 0 )
+            return VLC_ENOMEM;
+        i++;
+#       else
+         if( asprintf( &ppsz_dir_list[i], "%s" DIR_SEP "share" DIR_SEP "lua" DIR_SEP "%s",
                       psz_vlcpath, luadirname )  < 0 )
             return VLC_ENOMEM;
+        i++;
+#       endif
+
     }
 #   else
-    if( asprintf( &ppsz_dir_list[1],
-                  "share" DIR_SEP "%s", luadirname ) < 0 )
+    if( asprintf( &ppsz_dir_list[i],
+                  "share" DIR_SEP "lua" DIR_SEP "%s", luadirname ) < 0 )
         return VLC_ENOMEM;
 
 #   ifdef HAVE_SYS_STAT_H
     {
         struct stat stat_info;
-        if( ( utf8_stat( ppsz_dir_list[1], &stat_info ) == -1 )
+        if( ( utf8_stat( ppsz_dir_list[i], &stat_info ) == -1 )
             || !S_ISDIR( stat_info.st_mode ) )
         {
-            free(ppsz_dir_list[1]);
-            if( asprintf( &ppsz_dir_list[1],
-                          DATA_PATH DIR_SEP "%s", luadirname ) < 0 )
+            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
     return VLC_SUCCESS;
 }
@@ -450,7 +473,6 @@ int vlclua_scripts_batch_execute( vlc_object_t *p_this,
 {
     int i_ret = VLC_EGENERIC;
 
-    DIR   *dir           = NULL;
     char **ppsz_filelist = NULL;
     char **ppsz_fileend  = NULL;
     char **ppsz_file;
@@ -477,16 +499,8 @@ int vlclua_scripts_batch_execute( vlc_object_t *p_this,
             ppsz_filelist = NULL;
         }
 
-        if( dir )
-        {
-            closedir( dir );
-        }
-
         msg_Dbg( p_this, "Trying Lua scripts in %s", *ppsz_dir );
-        dir = utf8_opendir( *ppsz_dir );
-
-        if( !dir ) continue;
-        i_files = utf8_loaddir( dir, &ppsz_filelist, file_select,
+        i_files = utf8_scandir( *ppsz_dir, &ppsz_filelist, file_select,
                                 file_compare );
         if( i_files < 1 ) continue;
         ppsz_fileend = ppsz_filelist + i_files;
@@ -518,8 +532,6 @@ int vlclua_scripts_batch_execute( vlc_object_t *p_this,
     for( ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )
         free( *ppsz_dir );
 
-    if( dir ) closedir( dir );
-
     return i_ret;
 }
 
@@ -664,7 +676,7 @@ void __vlclua_read_options( vlc_object_t *p_this, lua_State *L,
 
 int __vlclua_playlist_add_internal( vlc_object_t *p_this, lua_State *L,
                                     playlist_t *p_playlist,
-                                    input_item_t *p_parent, vlc_bool_t b_play )
+                                    input_item_t *p_parent, bool b_play )
 {
     int i_count = 0;
 
@@ -744,16 +756,14 @@ 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 );
-                    else if( b_play ) /* Play */
+                    else /* Play or Enqueue (preparse) */
+                        /* FIXME: playlist_AddInput() can fail */
                         playlist_AddInput( p_playlist, p_input,
-                                           PLAYLIST_APPEND | PLAYLIST_GO,
-                                           PLAYLIST_END, VLC_TRUE, VLC_FALSE );
-                    else /* Enqueue */
-                        playlist_AddInput( p_playlist, p_input,
-                                           PLAYLIST_APPEND | PLAYLIST_PREPARSE,
-                                           PLAYLIST_END, VLC_TRUE, VLC_FALSE );
+                               PLAYLIST_APPEND | 
+                               ( b_play ? PLAYLIST_GO : PLAYLIST_PREPARSE ),
+                               PLAYLIST_END, true, false );
                     i_count ++; /* increment counter */
-
+                    vlc_gc_decref( p_input );
                     while( i_options > 0 )
                         free( ppsz_options[--i_options] );
                     free( ppsz_options );