demux: ts: only seek on pcr for current program
[vlc.git] / modules / lua / libs / configuration.c
blobbbb200527c0f20a71b5ef704fd363d8890d8403d
1 /*****************************************************************************
2 * configuration.c: Generic lua<->vlc config interface
3 *****************************************************************************
4 * Copyright (C) 2007-2008 the VideoLAN team
5 * $Id$
7 * Authors: Antoine Cellerier <dionoea at videolan tod org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
27 #ifndef _GNU_SOURCE
28 # define _GNU_SOURCE
29 #endif
31 #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
35 #include <vlc_common.h>
37 #include "../vlc.h"
38 #include "../libs.h"
40 /*****************************************************************************
41 * Config handling
42 *****************************************************************************/
43 static int vlclua_config_get( lua_State *L )
45 vlc_object_t * p_this = vlclua_get_this( L );
46 const char *psz_name = luaL_checkstring( L, 1 );
47 switch( config_GetType( psz_name ) )
49 case VLC_VAR_STRING:
51 char *psz = config_GetPsz( p_this, psz_name );
52 lua_pushstring( L, psz );
53 free( psz );
54 break;
57 case VLC_VAR_INTEGER:
58 lua_pushinteger( L, config_GetInt( p_this, psz_name ) );
59 break;
61 case VLC_VAR_BOOL:
62 lua_pushboolean( L, config_GetInt( p_this, psz_name ) );
63 break;
65 case VLC_VAR_FLOAT:
66 lua_pushnumber( L, config_GetFloat( p_this, psz_name ) );
67 break;
69 default:
70 return vlclua_error( L );
73 return 1;
76 static int vlclua_config_set( lua_State *L )
78 vlc_object_t *p_this = vlclua_get_this( L );
79 const char *psz_name = luaL_checkstring( L, 1 );
80 switch( config_GetType( psz_name ) )
82 case VLC_VAR_STRING:
83 config_PutPsz( p_this, psz_name, luaL_checkstring( L, 2 ) );
84 break;
86 case VLC_VAR_INTEGER:
87 config_PutInt( p_this, psz_name, luaL_checkinteger( L, 2 ) );
88 break;
90 case VLC_VAR_BOOL:
91 config_PutInt( p_this, psz_name, luaL_checkboolean( L, 2 ) );
92 break;
94 case VLC_VAR_FLOAT:
95 config_PutFloat( p_this, psz_name,
96 luaL_checknumber( L, 2 ) );
97 break;
99 default:
100 return vlclua_error( L );
102 return 0;
105 /*****************************************************************************
106 * Directories configuration
107 *****************************************************************************/
108 static int vlclua_datadir( lua_State *L )
110 char *psz_data = config_GetDataDir();
111 lua_pushstring( L, psz_data );
112 free( psz_data );
113 return 1;
116 static int vlclua_userdatadir( lua_State *L )
118 char *dir = config_GetUserDir( VLC_DATA_DIR );
119 lua_pushstring( L, dir );
120 free( dir );
121 return 1;
124 static int vlclua_homedir( lua_State *L )
126 char *home = config_GetUserDir( VLC_HOME_DIR );
127 lua_pushstring( L, home );
128 free( home );
129 return 1;
132 static int vlclua_configdir( lua_State *L )
134 char *dir = config_GetUserDir( VLC_CONFIG_DIR );
135 lua_pushstring( L, dir );
136 free( dir );
137 return 1;
140 static int vlclua_cachedir( lua_State *L )
142 char *dir = config_GetUserDir( VLC_CACHE_DIR );
143 lua_pushstring( L, dir );
144 free( dir );
145 return 1;
148 static int vlclua_datadir_list( lua_State *L )
150 const char *psz_dirname = luaL_checkstring( L, 1 );
151 char **ppsz_dir_list = NULL;
152 int i = 1;
154 if( vlclua_dir_list( psz_dirname, &ppsz_dir_list )
155 != VLC_SUCCESS )
156 return 0;
157 lua_newtable( L );
158 for( char **ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )
160 lua_pushstring( L, *ppsz_dir );
161 lua_rawseti( L, -2, i );
162 i ++;
164 vlclua_dir_list_free( ppsz_dir_list );
165 return 1;
168 /*****************************************************************************
170 *****************************************************************************/
171 static const luaL_Reg vlclua_config_reg[] = {
172 { "get", vlclua_config_get },
173 { "set", vlclua_config_set },
174 { "datadir", vlclua_datadir },
175 { "userdatadir", vlclua_userdatadir },
176 { "homedir", vlclua_homedir },
177 { "configdir", vlclua_configdir },
178 { "cachedir", vlclua_cachedir },
179 { "datadir_list", vlclua_datadir_list },
180 { NULL, NULL }
183 void luaopen_config( lua_State *L )
185 lua_newtable( L );
186 luaL_register( L, NULL, vlclua_config_reg );
187 lua_setfield( L, -2, "config" );