1 /*****************************************************************************
2 * configuration.c: Generic lua<->vlc config interface
3 *****************************************************************************
4 * Copyright (C) 2007-2008 the VideoLAN team
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 /*****************************************************************************
26 *****************************************************************************/
35 #include <vlc_common.h>
40 /*****************************************************************************
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
) )
51 char *psz
= config_GetPsz( p_this
, psz_name
);
52 lua_pushstring( L
, psz
);
58 lua_pushinteger( L
, config_GetInt( p_this
, psz_name
) );
62 lua_pushboolean( L
, config_GetInt( p_this
, psz_name
) );
66 lua_pushnumber( L
, config_GetFloat( p_this
, psz_name
) );
70 return vlclua_error( L
);
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
) )
83 config_PutPsz( p_this
, psz_name
, luaL_checkstring( L
, 2 ) );
87 config_PutInt( p_this
, psz_name
, luaL_checkinteger( L
, 2 ) );
91 config_PutInt( p_this
, psz_name
, luaL_checkboolean( L
, 2 ) );
95 config_PutFloat( p_this
, psz_name
,
96 luaL_checknumber( L
, 2 ) );
100 return vlclua_error( L
);
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
);
116 static int vlclua_userdatadir( lua_State
*L
)
118 char *dir
= config_GetUserDir( VLC_DATA_DIR
);
119 lua_pushstring( L
, dir
);
124 static int vlclua_homedir( lua_State
*L
)
126 char *home
= config_GetUserDir( VLC_HOME_DIR
);
127 lua_pushstring( L
, home
);
132 static int vlclua_configdir( lua_State
*L
)
134 char *dir
= config_GetUserDir( VLC_CONFIG_DIR
);
135 lua_pushstring( L
, dir
);
140 static int vlclua_cachedir( lua_State
*L
)
142 char *dir
= config_GetUserDir( VLC_CACHE_DIR
);
143 lua_pushstring( L
, dir
);
148 static int vlclua_datadir_list( lua_State
*L
)
150 const char *psz_dirname
= luaL_checkstring( L
, 1 );
151 char **ppsz_dir_list
= NULL
;
154 if( vlclua_dir_list( psz_dirname
, &ppsz_dir_list
)
158 for( char **ppsz_dir
= ppsz_dir_list
; *ppsz_dir
; ppsz_dir
++ )
160 lua_pushstring( L
, *ppsz_dir
);
161 lua_rawseti( L
, -2, i
);
164 vlclua_dir_list_free( ppsz_dir_list
);
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
},
183 void luaopen_config( lua_State
*L
)
186 luaL_register( L
, NULL
, vlclua_config_reg
);
187 lua_setfield( L
, -2, "config" );