1 /*****************************************************************************
2 * intf.c: Generic lua interface functions
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 *****************************************************************************/
38 #include <lua.h> /* Low level lua C API */
39 #include <lauxlib.h> /* Higher level C API */
44 /*****************************************************************************
46 *****************************************************************************/
47 static int vlc_osd_icon_from_string( const char *psz_name )
54 { { OSD_PAUSE_ICON, "pause" },
55 { OSD_PLAY_ICON, "play" },
56 { OSD_SPEAKER_ICON, "speaker" },
57 { OSD_MUTE_ICON, "mute" },
60 for( i = 0; pp_icons[i].psz_name; i++ )
62 if( !strcmp( psz_name, pp_icons[i].psz_name ) )
63 return pp_icons[i].i_icon;
68 static int vlclua_osd_icon( lua_State *L )
70 const char *psz_icon = luaL_checkstring( L, 1 );
71 int i_icon = vlc_osd_icon_from_string( psz_icon );
72 int i_chan = luaL_optint( L, 2, DEFAULT_CHAN );
74 return luaL_error( L, "\"%s\" is not a valid osd icon.", psz_icon );
77 vlc_object_t *p_this = vlclua_get_this( L );
78 vout_OSDIcon( p_this, i_chan, i_icon );
83 static int vlclua_osd_message( lua_State *L )
85 const char *psz_message = luaL_checkstring( L, 1 );
86 int i_chan = luaL_optint( L, 2, DEFAULT_CHAN );
87 vlc_object_t *p_this = vlclua_get_this( L );
88 vout_OSDMessage( p_this, i_chan, "%s", psz_message );
92 static int vlc_osd_slider_type_from_string( const char *psz_name )
99 { { OSD_HOR_SLIDER, "horizontal" },
100 { OSD_VERT_SLIDER, "vertical" },
103 for( i = 0; pp_types[i].psz_name; i++ )
105 if( !strcmp( psz_name, pp_types[i].psz_name ) )
106 return pp_types[i].i_type;
111 static int vlclua_osd_slider( lua_State *L )
113 int i_position = luaL_checkint( L, 1 );
114 const char *psz_type = luaL_checkstring( L, 2 );
115 int i_type = vlc_osd_slider_type_from_string( psz_type );
116 int i_chan = luaL_optint( L, 3, DEFAULT_CHAN );
118 return luaL_error( L, "\"%s\" is not a valid slider type.",
122 vlc_object_t *p_this = vlclua_get_this( L );
123 vout_OSDSlider( p_this, i_chan, i_position, i_type );
128 static int vlclua_spu_channel_register( lua_State *L )
131 vlc_object_t *p_this = vlclua_get_this( L );
132 vout_thread_t *p_vout = vlc_object_find( p_this, VLC_OBJECT_VOUT,
135 return luaL_error( L, "Unable to find vout." );
137 spu_Control( vout_GetSpu( p_vout ), SPU_CHANNEL_REGISTER, &i_chan );
138 vlc_object_release( p_vout );
139 lua_pushinteger( L, i_chan );
143 static int vlclua_spu_channel_clear( lua_State *L )
145 int i_chan = luaL_checkint( L, 1 );
146 vlc_object_t *p_this = vlclua_get_this( L );
147 vout_thread_t *p_vout = vlc_object_find( p_this, VLC_OBJECT_VOUT,
150 return luaL_error( L, "Unable to find vout." );
152 spu_Control( vout_GetSpu( p_vout ), SPU_CHANNEL_CLEAR, i_chan );
153 vlc_object_release( p_vout );
157 static int vlclua_menu_show( lua_State *L )
159 vlc_object_t *p_this = vlclua_get_this( L );
160 osd_MenuShow( p_this );
164 static int vlclua_menu_hide( lua_State *L )
166 vlc_object_t *p_this = vlclua_get_this( L );
167 osd_MenuHide( p_this );
171 static int vlclua_menu_prev( lua_State *L )
173 vlc_object_t *p_this = vlclua_get_this( L );
174 osd_MenuPrev( p_this );
178 static int vlclua_menu_next( lua_State *L )
180 vlc_object_t *p_this = vlclua_get_this( L );
181 osd_MenuNext( p_this );
185 static int vlclua_menu_up( lua_State *L )
187 vlc_object_t *p_this = vlclua_get_this( L );
188 osd_MenuUp( p_this );
192 static int vlclua_menu_down( lua_State *L )
194 vlc_object_t *p_this = vlclua_get_this( L );
195 osd_MenuDown( p_this );
199 static int vlclua_menu_activate( lua_State *L )
201 vlc_object_t *p_this = vlclua_get_this( L );
202 osd_MenuActivate( p_this );
206 /*****************************************************************************
208 *****************************************************************************/
209 static const luaL_Reg vlclua_osd_reg[] = {
210 { "icon", vlclua_osd_icon },
211 { "message", vlclua_osd_message },
212 { "slider", vlclua_osd_slider },
213 { "channel_register", vlclua_spu_channel_register },
214 { "channel_clear", vlclua_spu_channel_clear },
218 static const luaL_Reg vlclua_menu_reg[] = {
219 { "show", vlclua_menu_show },
220 { "hide", vlclua_menu_hide },
221 { "prev", vlclua_menu_prev },
222 { "next", vlclua_menu_next },
223 { "up", vlclua_menu_up },
224 { "down", vlclua_menu_down },
225 { "activate", vlclua_menu_activate },
229 void luaopen_osd( lua_State *L )
232 luaL_register( L, NULL, vlclua_osd_reg );
234 luaL_register( L, NULL, vlclua_menu_reg );
235 lua_setfield( L, -2, "menu" );
236 lua_setfield( L, -2, "osd" );