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 *****************************************************************************/
35 #include <vlc_common.h>
38 #include <lua.h> /* Low level lua C API */
39 #include <lauxlib.h> /* Higher level C API */
40 #include <lualib.h> /* Lua libs */
44 /*****************************************************************************
46 *****************************************************************************/
47 int vlclua_vlm_new( lua_State *L )
50 vlc_object_t *p_this = vlclua_get_this( L );
51 vlm_t *p_vlm = vlm_New( p_this );
54 __vlclua_push_vlc_object( L, (vlc_object_t*)p_vlm, NULL );
58 return luaL_error( L, "Cannot start VLM." );
61 int vlclua_vlm_delete( lua_State *L )
64 vlm_t *p_vlm = (vlm_t*)vlclua_checkobject( L, 1, VLC_OBJECT_GENERIC );
71 static void push_message( lua_State *L, vlm_message_t *message )
73 lua_createtable( L, 0, 2 );
74 lua_pushstring( L, message->psz_name );
75 lua_setfield( L, -2, "name" );
76 if( message->i_child > 0 )
79 lua_createtable( L, message->i_child, 0 );
80 for( i = 0; i < message->i_child; i++ )
82 lua_pushinteger( L, i+1 );
83 push_message( L, message->child[i] );
84 lua_settable( L, -3 );
86 lua_setfield( L, -2, "children" );
90 lua_pushstring( L, message->psz_value );
91 lua_setfield( L, -2, "value" );
95 int vlclua_vlm_execute_command( lua_State *L )
97 vlm_t *p_vlm = (vlm_t*)vlclua_checkobject( L, 1, VLC_OBJECT_GENERIC );
98 const char *psz_command = luaL_checkstring( L, 2 );
99 vlm_message_t *message;
101 i_ret = vlm_ExecuteCommand( p_vlm, psz_command, &message );
103 push_message( L, message );
104 vlm_MessageDelete( message );
105 return 1 + vlclua_push_ret( L, i_ret );
108 int vlclua_vlm_execute_command( lua_State *L )
110 return 1 + vlclua_push_ret( L, VLC_EGENERIC );