1 /*****************************************************************************
2 * objects.c: Generic lua VLM wrapper
3 *****************************************************************************
4 * Copyright (C) 2007 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 *****************************************************************************/
34 #include <lua.h> /* Low level lua C API */
35 #include <lauxlib.h> /* Higher level C API */
36 #include <lualib.h> /* Lua libs */
40 /*****************************************************************************
42 *****************************************************************************/
43 int vlclua_vlm_new( lua_State *L )
45 vlc_object_t *p_this = vlclua_get_this( L );
46 vlm_t *p_vlm = vlm_New( p_this );
48 return luaL_error( L, "Cannot start VLM." );
49 __vlclua_push_vlc_object( L, (vlc_object_t*)p_vlm, NULL );
53 int vlclua_vlm_delete( lua_State *L )
55 vlm_t *p_vlm = (vlm_t*)vlclua_checkobject( L, 1, VLC_OBJECT_VLM );
60 void push_message( lua_State *L, vlm_message_t *message );
61 void push_message( lua_State *L, vlm_message_t *message )
63 lua_createtable( L, 0, 2 );
64 lua_pushstring( L, message->psz_name );
65 lua_setfield( L, -2, "name" );
66 if( message->i_child > 0 )
69 lua_createtable( L, message->i_child, 0 );
70 for( i = 0; i < message->i_child; i++ )
72 lua_pushinteger( L, i+1 );
73 push_message( L, message->child[i] );
74 lua_settable( L, -3 );
76 lua_setfield( L, -2, "children" );
80 lua_pushstring( L, message->psz_value );
81 lua_setfield( L, -2, "value" );
85 int vlclua_vlm_execute_command( lua_State *L )
87 vlm_t *p_vlm = (vlm_t*)vlclua_checkobject( L, 1, VLC_OBJECT_VLM );
88 const char *psz_command = luaL_checkstring( L, 2 );
89 vlm_message_t *message;
90 vlm_ExecuteCommand( p_vlm, psz_command, &message );
92 push_message( L, message );
93 vlm_MessageDelete( message );