]> git.sesse.net Git - vlc/blob - modules/misc/lua/configuration.c
Add a new type of VLC Lua module: Interfaces.
[vlc] / modules / misc / lua / configuration.c
1 /*****************************************************************************
2  * configuration.c: Generic lua<->vlc config inteface
3  *****************************************************************************
4  * Copyright (C) 2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea at videolan tod org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #ifndef  _GNU_SOURCE
28 #   define  _GNU_SOURCE
29 #endif
30
31 #include <vlc/vlc.h>
32
33 #include <lua.h>        /* Low level lua C API */
34 #include <lauxlib.h>    /* Higher level C API */
35 #include <lualib.h>     /* Lua libs */
36
37 #include "vlc.h"
38
39 /*****************************************************************************
40  * Config handling
41  *****************************************************************************/
42 int vlclua_config_get( lua_State *L )
43 {
44     vlc_object_t * p_this = vlclua_get_this( L );
45     const char *psz_name;
46     psz_name = luaL_checkstring( L, 1 );
47     switch( config_GetType( p_this, psz_name ) )
48     {
49         case VLC_VAR_MODULE:
50         case VLC_VAR_STRING:
51         case VLC_VAR_FILE:
52         case VLC_VAR_DIRECTORY:
53             lua_pushstring( L, config_GetPsz( p_this, psz_name ) );
54             break;
55
56         case VLC_VAR_INTEGER:
57             lua_pushinteger( L, config_GetInt( p_this, psz_name ) );
58             break;
59
60         case VLC_VAR_BOOL:
61             lua_pushboolean( L, config_GetInt( p_this, psz_name ) );
62             break;
63
64         case VLC_VAR_FLOAT:
65             lua_pushnumber( L, config_GetFloat( p_this, psz_name ) );
66             break;
67
68         default:
69             return vlclua_error( L );
70
71     }
72     return 1;
73 }
74
75 int vlclua_config_set( lua_State *L )
76 {
77     vlc_object_t *p_this = vlclua_get_this( L );
78     const char *psz_name;
79     psz_name = luaL_checkstring( L, 1 );
80     switch( config_GetType( p_this, psz_name ) )
81     {
82         case VLC_VAR_MODULE:
83         case VLC_VAR_STRING:
84         case VLC_VAR_FILE:
85         case VLC_VAR_DIRECTORY:
86             config_PutPsz( p_this, psz_name, luaL_checkstring( L, 2 ) );
87             break;
88
89         case VLC_VAR_INTEGER:
90             config_PutInt( p_this, psz_name, luaL_checkint( L, 2 ) );
91             break;
92
93         case VLC_VAR_BOOL:
94             config_PutInt( p_this, psz_name, luaL_checkboolean( L, 2 ) );
95             break;
96
97         case VLC_VAR_FLOAT:
98             config_PutFloat( p_this, psz_name,
99                              luaL_checknumber( L, 2 ) );
100             break;
101
102         default:
103             return vlclua_error( L );
104     }
105     return 0;
106 }