1 /*****************************************************************************
2 * objects.c: Generic lua<->vlc object wrapper
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>
44 /*****************************************************************************
45 * Generic vlc_object_t wrapper creation
46 *****************************************************************************/
47 static int vlclua_object_release( lua_State *L )
49 vlc_object_t **p_obj = (vlc_object_t **)luaL_checkudata( L, 1, "vlc_object" );
51 vlc_object_release( *p_obj );
55 static int vlclua_object_find( lua_State *L )
61 static int vlclua_get_libvlc( lua_State *L )
63 libvlc_int_t *p_libvlc = vlclua_get_this( L )->p_libvlc;
64 vlc_object_hold( p_libvlc );
65 vlclua_push_vlc_object( L, p_libvlc );
69 static int vlclua_get_playlist( lua_State *L )
71 playlist_t *p_playlist = vlclua_get_playlist_internal( L );
74 vlc_object_hold( p_playlist );
75 vlclua_push_vlc_object( L, p_playlist );
77 else lua_pushnil( L );
81 static int vlclua_get_input( lua_State *L )
83 input_thread_t *p_input = vlclua_get_input_internal( L );
86 /* NOTE: p_input is already held by vlclua_get_input_internal() */
87 vlclua_push_vlc_object( L, p_input );
89 else lua_pushnil( L );
93 #undef vlclua_push_vlc_object
94 int vlclua_push_vlc_object( lua_State *L, vlc_object_t *p_obj )
96 vlc_object_t **udata = (vlc_object_t **)
97 lua_newuserdata( L, sizeof( vlc_object_t * ) );
100 if( luaL_newmetatable( L, "vlc_object" ) )
102 /* Hide the metatable */
103 lua_pushliteral( L, "none of your business" );
104 lua_setfield( L, -2, "__metatable" );
105 /* Set the garbage collector if needed */
106 lua_pushcfunction( L, vlclua_object_release );
107 lua_setfield( L, -2, "__gc" );
109 lua_setmetatable( L, -2 );
112 static int vlclua_get_vout( lua_State *L )
114 input_thread_t *p_input= vlclua_get_input_internal( L );
117 vout_thread_t *p_vout = input_GetVout( p_input );
118 vlc_object_release( p_input );
121 vlclua_push_vlc_object( L, (vlc_object_t *) p_vout );
128 static int vlclua_get_aout( lua_State *L )
130 input_thread_t *p_input= vlclua_get_input_internal( L );
133 audio_output_t *p_aout = input_GetAout( p_input );
134 vlc_object_release(p_input);
137 vlclua_push_vlc_object( L, (vlc_object_t *)p_aout );
144 /*****************************************************************************
146 *****************************************************************************/
147 static const luaL_Reg vlclua_object_reg[] = {
148 { "input", vlclua_get_input },
149 { "playlist", vlclua_get_playlist },
150 { "libvlc", vlclua_get_libvlc },
151 { "find", vlclua_object_find },
152 { "vout", vlclua_get_vout},
153 { "aout", vlclua_get_aout},
157 void luaopen_object( lua_State *L )
160 luaL_register( L, NULL, vlclua_object_reg );
161 lua_setfield( L, -2, "object" );