[vlc-commits] LUA: Add vlc.config.*dir to deprecate vlc.misc.*dir
Rémi Denis-Courmont
git at videolan.org
Fri Mar 16 16:30:06 CET 2012
vlc/vlc-2.0 | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Mar 11 14:29:54 2012 +0200| [2f8221abdcf485ebd3674d5878ccca1c4cfb0773] | committer: Jean-Baptiste Kempf
LUA: Add vlc.config.*dir to deprecate vlc.misc.*dir
This is partially cherry picked from commit f7ee3edcc510959cb85ffde3c350df8c36123c4e
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?a=commit;h=2f8221abdcf485ebd3674d5878ccca1c4cfb0773
---
modules/lua/libs/configuration.c | 69 +++++++++++++++++++++++++++++++
modules/lua/libs/misc.c | 1 +
share/lua/README.txt | 17 ++++----
share/lua/intf/http.lua | 2 +-
share/lua/intf/modules/httprequests.lua | 2 +-
share/lua/intf/test.lua | 12 +++--
6 files changed, 87 insertions(+), 16 deletions(-)
diff --git a/modules/lua/libs/configuration.c b/modules/lua/libs/configuration.c
index 7a4785f..5fd95cf 100644
--- a/modules/lua/libs/configuration.c
+++ b/modules/lua/libs/configuration.c
@@ -106,11 +106,80 @@ static int vlclua_config_set( lua_State *L )
}
/*****************************************************************************
+ * Directories configuration
+ *****************************************************************************/
+static int vlclua_datadir( lua_State *L )
+{
+ char *psz_data = config_GetDataDir( vlclua_get_this( L ) );
+ lua_pushstring( L, psz_data );
+ free( psz_data );
+ return 1;
+}
+
+static int vlclua_userdatadir( lua_State *L )
+{
+ char *dir = config_GetUserDir( VLC_DATA_DIR );
+ lua_pushstring( L, dir );
+ free( dir );
+ return 1;
+}
+
+static int vlclua_homedir( lua_State *L )
+{
+ char *home = config_GetUserDir( VLC_HOME_DIR );
+ lua_pushstring( L, home );
+ free( home );
+ return 1;
+}
+
+static int vlclua_configdir( lua_State *L )
+{
+ char *dir = config_GetUserDir( VLC_CONFIG_DIR );
+ lua_pushstring( L, dir );
+ free( dir );
+ return 1;
+}
+
+static int vlclua_cachedir( lua_State *L )
+{
+ char *dir = config_GetUserDir( VLC_CACHE_DIR );
+ lua_pushstring( L, dir );
+ free( dir );
+ return 1;
+}
+
+static int vlclua_datadir_list( lua_State *L )
+{
+ const char *psz_dirname = luaL_checkstring( L, 1 );
+ char **ppsz_dir_list = NULL;
+ int i = 1;
+
+ if( vlclua_dir_list( vlclua_get_this( L ), psz_dirname, &ppsz_dir_list )
+ != VLC_SUCCESS )
+ return 0;
+ lua_newtable( L );
+ for( char **ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )
+ {
+ lua_pushstring( L, *ppsz_dir );
+ lua_rawseti( L, -2, i );
+ i ++;
+ }
+ vlclua_dir_list_free( ppsz_dir_list );
+ return 1;
+}
+
+/*****************************************************************************
*
*****************************************************************************/
static const luaL_Reg vlclua_config_reg[] = {
{ "get", vlclua_config_get },
{ "set", vlclua_config_set },
+ { "datadir", vlclua_datadir },
+ { "userdatadir", vlclua_userdatadir },
+ { "homedir", vlclua_homedir },
+ { "configdir", vlclua_configdir },
+ { "cachedir", vlclua_cachedir },
+ { "datadir_list", vlclua_datadir_list },
{ NULL, NULL }
};
diff --git a/modules/lua/libs/misc.c b/modules/lua/libs/misc.c
index f98d28a..85aa651 100644
--- a/modules/lua/libs/misc.c
+++ b/modules/lua/libs/misc.c
@@ -199,6 +199,7 @@ static int vlclua_datadir_list( lua_State *L )
vlclua_dir_list_free( ppsz_dir_list );
return 1;
}
+
/*****************************************************************************
*
*****************************************************************************/
diff --git a/share/lua/README.txt b/share/lua/README.txt
index 52b5f5a..a945219 100644
--- a/share/lua/README.txt
+++ b/share/lua/README.txt
@@ -48,6 +48,14 @@ Configuration
-------------
config.get( name ): Get the VLC configuration option "name"'s value.
config.set( name, value ): Set the VLC configuration option "name"'s value.
+config.datadir(): Get the VLC data directory.
+config.userdatadir(): Get the user's VLC data directory.
+config.homedir(): Get the user's home directory.
+config.configdir(): Get the user's VLC config directory.
+config.cachedir(): Get the user's VLC cache directory.
+
+config.datadir_list( name ): FIXME: write description ... or ditch function
+ if it isn't useful anymore, we have datadir and userdatadir :)
Dialog
------
@@ -146,15 +154,6 @@ misc.version(): Get the VLC version string.
misc.copyright(): Get the VLC copyright statement.
misc.license(): Get the VLC license.
-misc.datadir(): Get the VLC data directory.
-misc.userdatadir(): Get the user's VLC data directory.
-misc.homedir(): Get the user's home directory.
-misc.configdir(): Get the user's VLC config directory.
-misc.cachedir(): Get the user's VLC cache directory.
-
-misc.datadir_list( name ): FIXME: write description ... or ditch function
- if it isn't useful anymore, we have datadir and userdatadir :)
-
misc.action_id( name ): get the id of the given action.
misc.mdate(): Get the current date (in microseconds).
diff --git a/share/lua/intf/http.lua b/share/lua/intf/http.lua
index 8814c56..de37820 100644
--- a/share/lua/intf/http.lua
+++ b/share/lua/intf/http.lua
@@ -243,7 +243,7 @@ function parse_url_request(request)
end
local function find_datadir(name)
- local list = vlc.misc.datadir_list(name)
+ local list = vlc.config.datadir_list(name)
for _, l in ipairs(list) do
local s = vlc.net.stat(l)
if s then
diff --git a/share/lua/intf/modules/httprequests.lua b/share/lua/intf/modules/httprequests.lua
index 262f618..8ce8995 100644
--- a/share/lua/intf/modules/httprequests.lua
+++ b/share/lua/intf/modules/httprequests.lua
@@ -380,7 +380,7 @@ getbrowsetable = function ()
result.element._array={}
if dir then
- if dir == "~" or dir == "file://~" then dir = vlc.misc.homedir() end
+ if dir == "~" or dir == "file://~" then dir = vlc.config.homedir() end
-- FIXME: hack for Win32 drive list
if dir~="" then
dir = common.realpath(dir.."/")
diff --git a/share/lua/intf/test.lua b/share/lua/intf/test.lua
index 20259e0..54dbf9a 100644
--- a/share/lua/intf/test.lua
+++ b/share/lua/intf/test.lua
@@ -16,11 +16,6 @@ vlc.msg.info('---- Testing misc functions ----')
vlc.msg.info('version: ' .. vlc.misc.version())
vlc.msg.info('copyright: ' .. vlc.misc.copyright())
vlc.msg.info('license: ' .. vlc.misc.license())
-vlc.msg.info('datadir: ' .. vlc.misc.datadir())
-vlc.msg.info('userdatadir: ' .. vlc.misc.userdatadir())
-vlc.msg.info('homedir: ' .. vlc.misc.homedir())
-vlc.msg.info('configdir: ' .. vlc.misc.configdir())
-vlc.msg.info('cachedir: ' .. vlc.misc.cachedir())
vlc.msg.info('mdate: ' .. vlc.misc.mdate())
vlc.msg.info(' * Testing the timer')
@@ -30,6 +25,13 @@ vlc.misc.mwait(vlc.misc.mdate()+1000000)
assert(timer_count == 1)
vlc.msg.info(' [done]')
+vlc.msg.info('---- Testing config functions ----')
+vlc.msg.info('datadir: ' .. vlc.config.datadir())
+vlc.msg.info('userdatadir: ' .. vlc.config.userdatadir())
+vlc.msg.info('homedir: ' .. vlc.config.homedir())
+vlc.msg.info('configdir: ' .. vlc.config.configdir())
+vlc.msg.info('cachedir: ' .. vlc.config.cachedir())
+
vlc.msg.info('---- Testing net functions ----')
vlc.msg.info(' * testing vlc.net.url_parse')
vlc.msg.info(' "filename.ext"')
More information about the vlc-commits
mailing list