[vlc-commits] Lua: look for scripts in $(pkglibdir) (refs #19324)

Rémi Denis-Courmont git at videolan.org
Sun Jan 14 17:58:12 CET 2018


vlc/vlc-3.0 | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jan 14 18:41:25 2018 +0200| [e9b031d915a7d73f01ca5009914fdc7cf18bfa1d] | committer: Rémi Denis-Courmont

Lua: look for scripts in $(pkglibdir) (refs #19324)

Add $(pkglibdir)/lua/TYPE as alternative to $(pkgdatadir)/lua/TYPE.

(cherry picked from commit c272f614521c7d63fe79f4445df280eff768c804)

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

 modules/lua/vlc.c | 49 ++++++++++++++++++++++++++-----------------------
 1 file changed, 26 insertions(+), 23 deletions(-)

diff --git a/modules/lua/vlc.c b/modules/lua/vlc.c
index 73c92d26b6..a7e48bb9ed 100644
--- a/modules/lua/vlc.c
+++ b/modules/lua/vlc.c
@@ -197,36 +197,39 @@ static int file_compare( const char **a, const char **b )
     return strcmp( *a, *b );
 }
 
-int vlclua_dir_list( const char *luadirname, char ***pppsz_dir_list )
+static char **vlclua_dir_list_append( char **restrict list, char *basedir,
+                                      const char *luadirname )
 {
-#define MAX_DIR_LIST_SIZE 5
-    *pppsz_dir_list = malloc(MAX_DIR_LIST_SIZE*sizeof(char *));
-    if (!*pppsz_dir_list)
-        return VLC_EGENERIC;
-    char **ppsz_dir_list = *pppsz_dir_list;
+    if (unlikely(basedir == NULL))
+        return list;
 
-    int i = 0;
-    char *datadir = config_GetUserDir( VLC_DATA_DIR );
+    if (likely(asprintf(list, "%s"DIR_SEP"lua"DIR_SEP"%s",
+                        basedir, luadirname) != -1))
+        list++;
 
-    if( likely(datadir != NULL)
-     && likely(asprintf( &ppsz_dir_list[i], "%s"DIR_SEP"lua"DIR_SEP"%s",
-                         datadir, luadirname ) != -1) )
-        i++;
-    free( datadir );
+    free(basedir);
+    return list;
+}
 
-    char *psz_datapath = config_GetDataDir();
-    if( likely(psz_datapath != NULL) )
-    {
-        if( likely(asprintf( &ppsz_dir_list[i], "%s"DIR_SEP"lua"DIR_SEP"%s",
-                              psz_datapath, luadirname ) != -1) )
-            i++;
-        free( psz_datapath );
-    }
+int vlclua_dir_list(const char *luadirname, char ***restrict listp)
+{
+    char **list = malloc(4 * sizeof(char *));
+    if (unlikely(list == NULL))
+        return VLC_EGENERIC;
+
+    *listp = list;
+
+    /* Lua scripts in user-specific data directory */
+    list = vlclua_dir_list_append(list, config_GetUserDir(VLC_DATA_DIR),
+                                  luadirname);
 
-    ppsz_dir_list[i] = NULL;
+    /* Tokenized Lua scripts in architecture-specific data directory */
+    list = vlclua_dir_list_append(list, config_GetLibDir(), luadirname);
 
-    assert( i < MAX_DIR_LIST_SIZE);
+    /* Source Lua Scripts in architecture-independent data directory */
+    list = vlclua_dir_list_append(list, config_GetDataDir(), luadirname);
 
+    *list = NULL;
     return VLC_SUCCESS;
 }
 



More information about the vlc-commits mailing list