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, SPU_DEFAULT_CHANNEL );
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_thread_t *p_vout = vlc_object_find( p_this, VLC_OBJECT_VOUT,
82 vout_OSDIcon( p_vout, i_chan, i_icon );
83 vlc_object_release( p_vout );
89 static int vlclua_osd_message( lua_State *L )
91 const char *psz_message = luaL_checkstring( L, 1 );
92 int i_chan = luaL_optint( L, 2, SPU_DEFAULT_CHANNEL );
93 vlc_object_t *p_this = vlclua_get_this( L );
94 vout_thread_t *p_vout = vlc_object_find( p_this, VLC_OBJECT_VOUT,
98 vout_OSDMessage( p_vout, i_chan, "%s", psz_message );
99 vlc_object_release( p_vout );
104 static int vlc_osd_slider_type_from_string( const char *psz_name )
109 const char *psz_name;
111 { { OSD_HOR_SLIDER, "horizontal" },
112 { OSD_VERT_SLIDER, "vertical" },
115 for( i = 0; pp_types[i].psz_name; i++ )
117 if( !strcmp( psz_name, pp_types[i].psz_name ) )
118 return pp_types[i].i_type;
123 static int vlclua_osd_slider( lua_State *L )
125 int i_position = luaL_checkint( L, 1 );
126 const char *psz_type = luaL_checkstring( L, 2 );
127 int i_type = vlc_osd_slider_type_from_string( psz_type );
128 int i_chan = luaL_optint( L, 3, SPU_DEFAULT_CHANNEL );
130 return luaL_error( L, "\"%s\" is not a valid slider type.",
134 vlc_object_t *p_this = vlclua_get_this( L );
135 vout_thread_t *p_vout = vlc_object_find( p_this, VLC_OBJECT_VOUT,
139 vout_OSDSlider( p_vout, i_chan, i_position, i_type );
140 vlc_object_release( p_vout );
146 static int vlclua_spu_channel_register( lua_State *L )
149 vlc_object_t *p_this = vlclua_get_this( L );
150 vout_thread_t *p_vout = vlc_object_find( p_this, VLC_OBJECT_VOUT,
153 return luaL_error( L, "Unable to find vout." );
155 i_chan = vout_RegisterSubpictureChannel( p_vout );
156 vlc_object_release( p_vout );
157 lua_pushinteger( L, i_chan );
161 static int vlclua_spu_channel_clear( lua_State *L )
163 int i_chan = luaL_checkint( L, 1 );
164 vlc_object_t *p_this = vlclua_get_this( L );
165 vout_thread_t *p_vout = vlc_object_find( p_this, VLC_OBJECT_VOUT,
168 return luaL_error( L, "Unable to find vout." );
170 vout_FlushSubpictureChannel( p_vout, i_chan );
171 vlc_object_release( p_vout );
175 static int vlclua_menu_show( lua_State *L )
177 vlc_object_t *p_this = vlclua_get_this( L );
178 osd_MenuShow( p_this );
182 static int vlclua_menu_hide( lua_State *L )
184 vlc_object_t *p_this = vlclua_get_this( L );
185 osd_MenuHide( p_this );
189 static int vlclua_menu_prev( lua_State *L )
191 vlc_object_t *p_this = vlclua_get_this( L );
192 osd_MenuPrev( p_this );
196 static int vlclua_menu_next( lua_State *L )
198 vlc_object_t *p_this = vlclua_get_this( L );
199 osd_MenuNext( p_this );
203 static int vlclua_menu_up( lua_State *L )
205 vlc_object_t *p_this = vlclua_get_this( L );
206 osd_MenuUp( p_this );
210 static int vlclua_menu_down( lua_State *L )
212 vlc_object_t *p_this = vlclua_get_this( L );
213 osd_MenuDown( p_this );
217 static int vlclua_menu_activate( lua_State *L )
219 vlc_object_t *p_this = vlclua_get_this( L );
220 osd_MenuActivate( p_this );
224 /*****************************************************************************
226 *****************************************************************************/
227 static const luaL_Reg vlclua_osd_reg[] = {
228 { "icon", vlclua_osd_icon },
229 { "message", vlclua_osd_message },
230 { "slider", vlclua_osd_slider },
231 { "channel_register", vlclua_spu_channel_register },
232 { "channel_clear", vlclua_spu_channel_clear },
236 static const luaL_Reg vlclua_menu_reg[] = {
237 { "show", vlclua_menu_show },
238 { "hide", vlclua_menu_hide },
239 { "prev", vlclua_menu_prev },
240 { "next", vlclua_menu_next },
241 { "up", vlclua_menu_up },
242 { "down", vlclua_menu_down },
243 { "activate", vlclua_menu_activate },
247 void luaopen_osd( lua_State *L )
250 luaL_register( L, NULL, vlclua_osd_reg );
252 luaL_register( L, NULL, vlclua_menu_reg );
253 lua_setfield( L, -2, "menu" );
254 lua_setfield( L, -2, "osd" );