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 */
45 /*****************************************************************************
47 *****************************************************************************/
48 static int vlc_osd_icon_from_string( const char *psz_name )
55 { { OSD_PAUSE_ICON, "pause" },
56 { OSD_PLAY_ICON, "play" },
57 { OSD_SPEAKER_ICON, "speaker" },
58 { OSD_MUTE_ICON, "mute" },
61 for( i = 0; pp_icons[i].psz_name; i++ )
63 if( !strcmp( psz_name, pp_icons[i].psz_name ) )
64 return pp_icons[i].i_icon;
69 static int vlclua_osd_icon( lua_State *L )
71 const char *psz_icon = luaL_checkstring( L, 1 );
72 int i_icon = vlc_osd_icon_from_string( psz_icon );
73 int i_chan = luaL_optint( L, 2, SPU_DEFAULT_CHANNEL );
75 return luaL_error( L, "\"%s\" is not a valid osd icon.", psz_icon );
77 input_thread_t *p_input = vlclua_get_input_internal( L );
80 vout_thread_t *p_vout = input_GetVout( p_input );
83 vout_OSDIcon( p_vout, i_chan, i_icon );
84 vlc_object_release( p_vout );
86 vlc_object_release( p_input );
91 static int vlclua_osd_message( lua_State *L )
93 const char *psz_message = luaL_checkstring( L, 1 );
94 int i_chan = luaL_optint( L, 2, SPU_DEFAULT_CHANNEL );
96 input_thread_t *p_input = vlclua_get_input_internal( L );
99 vout_thread_t *p_vout = input_GetVout( p_input );
102 vout_OSDMessage( p_vout, i_chan, "%s", psz_message );
103 vlc_object_release( p_vout );
105 vlc_object_release( p_input );
110 static int vlc_osd_slider_type_from_string( const char *psz_name )
115 const char *psz_name;
117 { { OSD_HOR_SLIDER, "horizontal" },
118 { OSD_VERT_SLIDER, "vertical" },
121 for( i = 0; pp_types[i].psz_name; i++ )
123 if( !strcmp( psz_name, pp_types[i].psz_name ) )
124 return pp_types[i].i_type;
129 static int vlclua_osd_slider( lua_State *L )
131 int i_position = luaL_checkint( L, 1 );
132 const char *psz_type = luaL_checkstring( L, 2 );
133 int i_type = vlc_osd_slider_type_from_string( psz_type );
134 int i_chan = luaL_optint( L, 3, SPU_DEFAULT_CHANNEL );
136 return luaL_error( L, "\"%s\" is not a valid slider type.",
139 input_thread_t *p_input = vlclua_get_input_internal( L );
142 vout_thread_t *p_vout = input_GetVout( p_input );
145 vout_OSDSlider( p_vout, i_chan, i_position, i_type );
146 vlc_object_release( p_vout );
148 vlc_object_release( p_input );
153 static int vlclua_spu_channel_register( lua_State *L )
155 input_thread_t *p_input = vlclua_get_input_internal( L );
157 return luaL_error( L, "Unable to find input." );
159 vout_thread_t *p_vout = input_GetVout( p_input );
162 vlc_object_release( p_input );
163 return luaL_error( L, "Unable to find vout." );
166 int i_chan = vout_RegisterSubpictureChannel( p_vout );
167 vlc_object_release( p_vout );
168 vlc_object_release( p_input );
169 lua_pushinteger( L, i_chan );
173 static int vlclua_spu_channel_clear( lua_State *L )
175 int i_chan = luaL_checkint( L, 1 );
176 input_thread_t *p_input = vlclua_get_input_internal( L );
178 return luaL_error( L, "Unable to find input." );
179 vout_thread_t *p_vout = input_GetVout( p_input );
182 vlc_object_release( p_input );
183 return luaL_error( L, "Unable to find vout." );
186 vout_FlushSubpictureChannel( p_vout, i_chan );
187 vlc_object_release( p_vout );
188 vlc_object_release( p_input );
192 static int vlclua_menu_show( lua_State *L )
194 vlc_object_t *p_this = vlclua_get_this( L );
195 osd_MenuShow( p_this );
199 static int vlclua_menu_hide( lua_State *L )
201 vlc_object_t *p_this = vlclua_get_this( L );
202 osd_MenuHide( p_this );
206 static int vlclua_menu_prev( lua_State *L )
208 vlc_object_t *p_this = vlclua_get_this( L );
209 osd_MenuPrev( p_this );
213 static int vlclua_menu_next( lua_State *L )
215 vlc_object_t *p_this = vlclua_get_this( L );
216 osd_MenuNext( p_this );
220 static int vlclua_menu_up( lua_State *L )
222 vlc_object_t *p_this = vlclua_get_this( L );
223 osd_MenuUp( p_this );
227 static int vlclua_menu_down( lua_State *L )
229 vlc_object_t *p_this = vlclua_get_this( L );
230 osd_MenuDown( p_this );
234 static int vlclua_menu_activate( lua_State *L )
236 vlc_object_t *p_this = vlclua_get_this( L );
237 osd_MenuActivate( p_this );
241 /*****************************************************************************
243 *****************************************************************************/
244 static const luaL_Reg vlclua_osd_reg[] = {
245 { "icon", vlclua_osd_icon },
246 { "message", vlclua_osd_message },
247 { "slider", vlclua_osd_slider },
248 { "channel_register", vlclua_spu_channel_register },
249 { "channel_clear", vlclua_spu_channel_clear },
253 static const luaL_Reg vlclua_menu_reg[] = {
254 { "show", vlclua_menu_show },
255 { "hide", vlclua_menu_hide },
256 { "prev", vlclua_menu_prev },
257 { "next", vlclua_menu_next },
258 { "up", vlclua_menu_up },
259 { "down", vlclua_menu_down },
260 { "activate", vlclua_menu_activate },
264 void luaopen_osd( lua_State *L )
267 luaL_register( L, NULL, vlclua_osd_reg );
269 luaL_register( L, NULL, vlclua_menu_reg );
270 lua_setfield( L, -2, "menu" );
271 lua_setfield( L, -2, "osd" );