1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
/*****************************************************************************
* objects.c: Generic lua<->vlc object wrapper
*****************************************************************************
* Copyright (C) 2007-2008 the VideoLAN team
* $Id$
*
* Authors: Antoine Cellerier <dionoea at videolan tod org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#ifndef _GNU_SOURCE
# define _GNU_SOURCE
#endif
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vlc_common.h>
#include <vlc_vout.h>
#include "../vlc.h"
#include "../libs.h"
#include "objects.h"
#include "input.h"
/*****************************************************************************
* Generic vlc_object_t wrapper creation
*****************************************************************************/
static int vlclua_object_release( lua_State *L )
{
vlc_object_t **p_obj = (vlc_object_t **)luaL_checkudata( L, 1, "vlc_object" );
lua_pop( L, 1 );
vlc_object_release( *p_obj );
return 0;
}
static int vlclua_object_find( lua_State *L )
{
lua_pushnil( L );
return 1;
}
static int vlclua_get_libvlc( lua_State *L )
{
libvlc_int_t *p_libvlc = vlclua_get_this( L )->obj.libvlc;
vlc_object_hold( p_libvlc );
vlclua_push_vlc_object( L, p_libvlc );
return 1;
}
static int vlclua_get_playlist( lua_State *L )
{
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
if( p_playlist )
{
vlc_object_hold( p_playlist );
vlclua_push_vlc_object( L, p_playlist );
}
else lua_pushnil( L );
return 1;
}
static int vlclua_get_input( lua_State *L )
{
input_thread_t *p_input = vlclua_get_input_internal( L );
if( p_input )
{
/* NOTE: p_input is already held by vlclua_get_input_internal() */
vlclua_push_vlc_object( L, p_input );
}
else lua_pushnil( L );
return 1;
}
#undef vlclua_push_vlc_object
int vlclua_push_vlc_object( lua_State *L, vlc_object_t *p_obj )
{
vlc_object_t **udata = (vlc_object_t **)
lua_newuserdata( L, sizeof( vlc_object_t * ) );
*udata = p_obj;
if( luaL_newmetatable( L, "vlc_object" ) )
{
/* Hide the metatable */
lua_pushliteral( L, "none of your business" );
lua_setfield( L, -2, "__metatable" );
/* Set the garbage collector if needed */
lua_pushcfunction( L, vlclua_object_release );
lua_setfield( L, -2, "__gc" );
}
lua_setmetatable( L, -2 );
return 1;
}
static int vlclua_get_vout( lua_State *L )
{
input_thread_t *p_input = vlclua_get_input_internal( L );
if( p_input )
{
vout_thread_t *p_vout = input_GetVout( p_input );
vlc_object_release( p_input );
if(p_vout)
{
vlclua_push_vlc_object( L, (vlc_object_t *) p_vout );
return 1;
}
}
lua_pushnil( L );
return 1;
}
static int vlclua_get_aout( lua_State *L )
{
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
if( p_playlist != NULL )
{
audio_output_t *p_aout = playlist_GetAout( p_playlist );
if( p_aout != NULL )
{
vlclua_push_vlc_object( L, (vlc_object_t *)p_aout );
return 1;
}
}
lua_pushnil( L );
return 1;
}
/*****************************************************************************
*
*****************************************************************************/
static const luaL_Reg vlclua_object_reg[] = {
{ "input", vlclua_get_input },
{ "playlist", vlclua_get_playlist },
{ "libvlc", vlclua_get_libvlc },
{ "find", vlclua_object_find },
{ "vout", vlclua_get_vout},
{ "aout", vlclua_get_aout},
{ NULL, NULL }
};
void luaopen_object( lua_State *L )
{
lua_newtable( L );
luaL_register( L, NULL, vlclua_object_reg );
lua_setfield( L, -2, "object" );
}
|