[vlc-devel] commit: Also load .luac files. (Antoine Cellerier )

git version control git at videolan.org
Sat Feb 6 16:00:55 CET 2010


vlc | branch: master | Antoine Cellerier <dionoea at videolan.org> | Sat Feb  6 15:51:00 2010 +0100| [4417c123aadb9eb8a4eb03f1cdddd171071f76db] | committer: Antoine Cellerier 

Also load .luac files.

Lua source code can be compiled into binary files to speedup loading using the luac command line utility. VLC will first try loading the .luac module and fallback to .lua if it fails.
(And factorize code)

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

 modules/misc/lua/intf.c               |   31 +-----------------------
 modules/misc/lua/services_discovery.c |   33 +-------------------------
 modules/misc/lua/vlc.c                |   42 ++++++++++++++++++++++++++++++++-
 modules/misc/lua/vlc.h                |    1 +
 4 files changed, 44 insertions(+), 63 deletions(-)

diff --git a/modules/misc/lua/intf.c b/modules/misc/lua/intf.c
index 70e590a..b9e1737 100644
--- a/modules/misc/lua/intf.c
+++ b/modules/misc/lua/intf.c
@@ -59,35 +59,6 @@ static const char * const ppsz_intf_options[] = { "intf", "config", NULL };
 /*****************************************************************************
  *
  *****************************************************************************/
-static char *FindFile( vlc_object_t *p_this, const char *psz_name )
-{
-    char  *ppsz_dir_list[] = { NULL, NULL, NULL, NULL };
-    char **ppsz_dir;
-    vlclua_dir_list( p_this, "intf", ppsz_dir_list );
-    for( ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )
-    {
-        char *psz_filename;
-        struct stat st;
-
-        if( asprintf( &psz_filename, "%s"DIR_SEP"%s.lua", *ppsz_dir,
-                      psz_name ) < 0 )
-        {
-            vlclua_dir_list_free( ppsz_dir_list );
-            return NULL;
-        }
-
-        if( utf8_stat( psz_filename, &st ) == 0
-         && S_ISREG( st.st_mode ) )
-        {
-            vlclua_dir_list_free( ppsz_dir_list );
-            return psz_filename;
-        }
-        free( psz_filename );
-    }
-    vlclua_dir_list_free( ppsz_dir_list );
-    return NULL;
-}
-
 static inline void luaL_register_submodule( lua_State *L, const char *psz_name,
                                             const luaL_Reg *l )
 {
@@ -182,7 +153,7 @@ int Open_LuaIntf( vlc_object_t *p_this )
         return VLC_ENOMEM;
     }
     p_sys = p_intf->p_sys;
-    p_sys->psz_filename = FindFile( p_this, psz_name );
+    p_sys->psz_filename = vlclua_find_file( p_this, "intf", psz_name );
     if( !p_sys->psz_filename )
     {
         msg_Err( p_intf, "Couldn't find lua interface script \"%s\".",
diff --git a/modules/misc/lua/services_discovery.c b/modules/misc/lua/services_discovery.c
index d37133d..8e02168 100644
--- a/modules/misc/lua/services_discovery.c
+++ b/modules/misc/lua/services_discovery.c
@@ -50,37 +50,6 @@ struct services_discovery_sys_t
 static const luaL_Reg p_reg[] = { { NULL, NULL } };
 
 /*****************************************************************************
- *
- *****************************************************************************/
-static char *FindFile( vlc_object_t *p_this, const char *psz_name )
-{
-    char  *ppsz_dir_list[] = { NULL, NULL, NULL, NULL };
-    char **ppsz_dir;
-    vlclua_dir_list( p_this, "sd", ppsz_dir_list );
-    for( ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )
-    {
-        char *psz_filename;
-        FILE *fp;
-        if( asprintf( &psz_filename, "%s"DIR_SEP"%s.lua", *ppsz_dir,
-                      psz_name ) < 0 )
-        {
-            vlclua_dir_list_free( ppsz_dir_list );
-            return NULL;
-        }
-        fp = utf8_fopen( psz_filename, "r" );
-        if( fp )
-        {
-            fclose( fp );
-            vlclua_dir_list_free( ppsz_dir_list );
-            return psz_filename;
-        }
-        free( psz_filename );
-    }
-    vlclua_dir_list_free( ppsz_dir_list );
-    return NULL;
-}
-
-/*****************************************************************************
  * Open: initialize and create stuff
  *****************************************************************************/
 int Open_LuaSD( vlc_object_t *p_this )
@@ -95,7 +64,7 @@ int Open_LuaSD( vlc_object_t *p_this )
     if( !( p_sys = malloc( sizeof( services_discovery_sys_t ) ) ) )
         return VLC_ENOMEM;
     p_sd->p_sys = p_sys;
-    p_sys->psz_filename = FindFile( p_this, psz_name );
+    p_sys->psz_filename = vlclua_find_file( p_this, "sd", psz_name );
     if( !p_sys->psz_filename )
     {
         msg_Err( p_sd, "Couldn't find lua services discovery script \"%s\".",
diff --git a/modules/misc/lua/vlc.c b/modules/misc/lua/vlc.c
index dd1cb34..591206a 100644
--- a/modules/misc/lua/vlc.c
+++ b/modules/misc/lua/vlc.c
@@ -41,6 +41,7 @@
 #include <vlc_charset.h>
 #include <vlc_aout.h>
 #include <vlc_services_discovery.h>
+#include <sys/stat.h>
 
 #include <lua.h>        /* Low level lua C API */
 #include <lauxlib.h>    /* Higher level C API */
@@ -129,10 +130,18 @@ vlc_module_end ()
 /*****************************************************************************
  *
  *****************************************************************************/
+static const char *ppsz_lua_exts[] = { ".luac", ".lua", NULL };
 static int file_select( const char *file )
 {
     int i = strlen( file );
-    return i > 4 && !strcmp( file+i-4, ".lua" );
+    int j;
+    for( j = 0; ppsz_lua_exts[j]; j++ )
+    {
+        int l = strlen( ppsz_lua_exts[j] );
+        if( !strcmp( file+i-l, ppsz_lua_exts[j] ) )
+            return 1;
+    }
+    return 0;
 }
 
 static int file_compare( const char **a, const char **b )
@@ -248,6 +257,37 @@ int vlclua_scripts_batch_execute( vlc_object_t *p_this,
     return i_ret;
 }
 
+char *vlclua_find_file( vlc_object_t *p_this, const char *psz_luadirname, const char *psz_name )
+{
+    char  *ppsz_dir_list[] = { NULL, NULL, NULL, NULL };
+    char **ppsz_dir;
+    vlclua_dir_list( p_this, psz_luadirname, ppsz_dir_list );
+    for( ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )
+    {
+        for( const char **ppsz_ext = ppsz_lua_exts; *ppsz_ext; ppsz_ext++ )
+        {
+            char *psz_filename;
+            struct stat st;
+
+            if( asprintf( &psz_filename, "%s"DIR_SEP"%s%s", *ppsz_dir,
+                          psz_name, *ppsz_ext ) < 0 )
+            {
+                vlclua_dir_list_free( ppsz_dir_list );
+                return NULL;
+            }
+
+            if( utf8_stat( psz_filename, &st ) == 0
+                && S_ISREG( st.st_mode ) )
+            {
+                vlclua_dir_list_free( ppsz_dir_list );
+                return psz_filename;
+            }
+            free( psz_filename );
+        }
+    }
+    vlclua_dir_list_free( ppsz_dir_list );
+    return NULL;
+}
 
 /*****************************************************************************
  * Meta data setters utility.
diff --git a/modules/misc/lua/vlc.h b/modules/misc/lua/vlc.h
index 8215dbc..34a0878 100644
--- a/modules/misc/lua/vlc.h
+++ b/modules/misc/lua/vlc.h
@@ -110,6 +110,7 @@ int vlclua_scripts_batch_execute( vlc_object_t *p_this, const char * luadirname,
         lua_State * L, void * user_data );
 int vlclua_dir_list( vlc_object_t *p_this, const char *luadirname, char **ppsz_dir_list );
 void vlclua_dir_list_free( char **ppsz_dir_list );
+char *vlclua_find_file( vlc_object_t *p_this, const char *psz_luadirname, const char *psz_name );
 
 /*****************************************************************************
  * Playlist and meta data internal utilities.




More information about the vlc-devel mailing list