Commit 95addd57 authored by Antoine Cellerier's avatar Antoine Cellerier

Implement Lua objects in the C code directly. Fix most type checks. Move every thing arround.

parent e9315c82
SOURCES_lua = playlist.c meta.c intf.c vlc.c vlc.h callbacks.c objects.c variables.c configuration.c net.c vlm.c httpd.c acl.c sd.c SOURCES_lua = \
intf.c \
meta.c \
demux.c \
vlc.c \
vlc.h \
libs.h \
libs/acl.c \
libs/configuration.c \
libs/httpd.c \
libs/input.c \
libs/input.h \
libs/messages.c \
libs/misc.c \
libs/net.c \
libs/objects.c \
libs/objects.h \
libs/osd.c \
libs/playlist.c \
libs/playlist.h \
libs/sd.c \
libs/stream.c \
libs/strings.c \
libs/variables.c \
libs/variables.h \
libs/video.c \
libs/vlm.c \
libs/volume.c \
$(NULL)
libvlc_LTLIBRARIES += liblua_plugin.la libvlc_LTLIBRARIES += liblua_plugin.la
/***************************************************************************** /*****************************************************************************
* playlist.c : Lua playlist demux module * demux.c : Lua playlist demux module
***************************************************************************** *****************************************************************************
* Copyright (C) 2007 the VideoLAN team * Copyright (C) 2007-2008 the VideoLAN team
* $Id$ * $Id$
* *
* Authors: Antoine Cellerier <dionoea at videolan tod org> * Authors: Antoine Cellerier <dionoea at videolan tod org>
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#endif #endif
#include "vlc.h" #include "vlc.h"
#include "libs.h"
/***************************************************************************** /*****************************************************************************
...@@ -49,7 +50,7 @@ static int Demux( demux_t *p_demux ); ...@@ -49,7 +50,7 @@ static int Demux( demux_t *p_demux );
static int Control( demux_t *p_demux, int i_query, va_list args ); static int Control( demux_t *p_demux, int i_query, va_list args );
/***************************************************************************** /*****************************************************************************
* * Demux specific functions
*****************************************************************************/ *****************************************************************************/
struct demux_sys_t struct demux_sys_t
{ {
...@@ -57,10 +58,6 @@ struct demux_sys_t ...@@ -57,10 +58,6 @@ struct demux_sys_t
char *psz_filename; char *psz_filename;
}; };
/*****************************************************************************
*
*****************************************************************************/
static int vlclua_demux_peek( lua_State *L ) static int vlclua_demux_peek( lua_State *L )
{ {
demux_t *p_demux = (demux_t *)vlclua_get_this( L ); demux_t *p_demux = (demux_t *)vlclua_get_this( L );
...@@ -97,17 +94,13 @@ static int vlclua_demux_readline( lua_State *L ) ...@@ -97,17 +94,13 @@ static int vlclua_demux_readline( lua_State *L )
return 1; return 1;
} }
/*****************************************************************************
*
*****************************************************************************/
/* Functions to register */ /* Functions to register */
static luaL_Reg p_reg[] = static luaL_Reg p_reg[] =
{ {
{ "peek", vlclua_demux_peek }, { "peek", vlclua_demux_peek },
{ "decode_uri", vlclua_decode_uri },
{ "resolve_xml_special_chars", vlclua_resolve_xml_special_chars },
{ "msg_dbg", vlclua_msg_dbg },
{ "msg_warn", vlclua_msg_warn },
{ "msg_err", vlclua_msg_err },
{ "msg_info", vlclua_msg_info },
{ NULL, NULL } { NULL, NULL }
}; };
...@@ -215,6 +208,8 @@ int Import_LuaPlaylist( vlc_object_t *p_this ) ...@@ -215,6 +208,8 @@ int Import_LuaPlaylist( vlc_object_t *p_this )
luaL_openlibs( L ); /* FIXME: Don't open all the libs? */ luaL_openlibs( L ); /* FIXME: Don't open all the libs? */
luaL_register( L, "vlc", p_reg ); luaL_register( L, "vlc", p_reg );
luaopen_msg( L );
luaopen_strings( L );
lua_pushlightuserdata( L, p_demux ); lua_pushlightuserdata( L, p_demux );
lua_setfield( L, -2, "private" ); lua_setfield( L, -2, "private" );
lua_pushstring( L, p_demux->psz_path ); lua_pushstring( L, p_demux->psz_path );
......
This diff is collapsed.
/*****************************************************************************
* libs.h: VLC Lua wrapper libraries
*****************************************************************************
* Copyright (C) 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.
*****************************************************************************/
#ifndef VLC_LUA_LIBS_H
#define VLC_LUA_LIBS_H
void luaopen_acl( lua_State * );
void luaopen_config( lua_State * );
void luaopen_volume( lua_State * );
void luaopen_httpd( lua_State * );
void luaopen_input( lua_State * );
void luaopen_msg( lua_State * );
void luaopen_misc( lua_State * );
void luaopen_net( lua_State * );
void luaopen_object( lua_State * );
void luaopen_osd( lua_State * );
void luaopen_playlist( lua_State * );
void luaopen_sd( lua_State * );
void luaopen_stream( lua_State * );
void luaopen_strings( lua_State * );
void luaopen_variables( lua_State * );
void luaopen_video( lua_State * );
void luaopen_vlm( lua_State * );
void luaopen_volume( lua_State * );
#endif
/***************************************************************************** /*****************************************************************************
* acl.c: Access list related functions * acl.c: Access list related functions
***************************************************************************** *****************************************************************************
* Copyright (C) 2007 the VideoLAN team * Copyright (C) 2007-2008 the VideoLAN team
* $Id$ * $Id$
* *
* Authors: Antoine Cellerier <dionoea at videolan tod org> * Authors: Antoine Cellerier <dionoea at videolan tod org>
...@@ -37,71 +37,111 @@ ...@@ -37,71 +37,111 @@
#include <lua.h> /* Low level lua C API */ #include <lua.h> /* Low level lua C API */
#include <lauxlib.h> /* Higher level C API */ #include <lauxlib.h> /* Higher level C API */
#include <lualib.h> /* Lua libs */
#include "vlc.h" #include "../vlc.h"
#include "../libs.h"
/***************************************************************************** /*****************************************************************************
* *
*****************************************************************************/ *****************************************************************************/
int vlclua_acl_create( lua_State *L ) static int vlclua_acl_create_inner( lua_State *, vlc_acl_t * );
static int vlclua_acl_delete( lua_State * );
static int vlclua_acl_check( lua_State * );
static int vlclua_acl_duplicate( lua_State * );
static int vlclua_acl_add_host( lua_State * );
static int vlclua_acl_add_net( lua_State * );
static int vlclua_acl_load_file( lua_State * );
static const luaL_Reg vlclua_acl_reg[] = {
{ "check", vlclua_acl_check },
{ "duplicate", vlclua_acl_duplicate },
{ "add_host", vlclua_acl_add_host },
{ "add_net", vlclua_acl_add_net },
{ "load_file", vlclua_acl_load_file },
{ NULL, NULL }
};
static int vlclua_acl_create( lua_State *L )
{ {
vlc_object_t *p_this = vlclua_get_this( L ); vlc_object_t *p_this = vlclua_get_this( L );
bool b_allow = luaL_checkboolean( L, 1 ) ? true : false; bool b_allow = luaL_checkboolean( L, 1 ) ? true : false;
vlc_acl_t *p_acl = ACL_Create( p_this, b_allow ); vlc_acl_t *p_acl = ACL_Create( p_this, b_allow );
return vlclua_acl_create_inner( L, p_acl );
}
static int vlclua_acl_create_inner( lua_State *L, vlc_acl_t *p_acl )
{
if( !p_acl ) if( !p_acl )
return luaL_error( L, "ACL creation failed." ); return luaL_error( L, "ACL creation failed." );
lua_pushlightuserdata( L, p_acl ); /* FIXME */
vlc_acl_t **pp_acl = lua_newuserdata( L, sizeof( vlc_acl_t * ) );
*pp_acl = p_acl;
if( luaL_newmetatable( L, "acl" ) )
{
lua_newtable( L );
luaL_register( L, NULL, vlclua_acl_reg );
lua_setfield( L, -2, "__index" );
lua_pushcfunction( L, vlclua_acl_delete );
lua_setfield( L, -2, "__gc" );
}
lua_setmetatable( L, -2 );
return 1; return 1;
} }
int vlclua_acl_delete( lua_State *L ) static int vlclua_acl_delete( lua_State *L )
{ {
vlc_acl_t *p_acl = (vlc_acl_t*)luaL_checklightuserdata( L, 1 ); vlc_acl_t **pp_acl = (vlc_acl_t**)luaL_checkudata( L, 1, "acl" );
ACL_Destroy( p_acl ); ACL_Destroy( *pp_acl );
return 0; return 0;
} }
int vlclua_acl_check( lua_State *L ) static int vlclua_acl_check( lua_State *L )
{ {
vlc_acl_t *p_acl = (vlc_acl_t*)luaL_checklightuserdata( L, 1 ); vlc_acl_t **pp_acl = (vlc_acl_t**)luaL_checkudata( L, 1, "acl" );
const char *psz_ip = luaL_checkstring( L, 2 ); const char *psz_ip = luaL_checkstring( L, 2 );
lua_pushinteger( L, ACL_Check( p_acl, psz_ip ) ); lua_pushinteger( L, ACL_Check( *pp_acl, psz_ip ) );
return 1; return 1;
} }
int vlclua_acl_duplicate( lua_State *L ) static int vlclua_acl_duplicate( lua_State *L )
{ {
vlc_object_t *p_this = vlclua_get_this( L ); vlc_object_t *p_this = vlclua_get_this( L );
vlc_acl_t *p_acl = (vlc_acl_t*)luaL_checklightuserdata( L, 1 ); vlc_acl_t **pp_acl = (vlc_acl_t**)luaL_checkudata( L, 1, "acl" );
vlc_acl_t *p_acl_new = ACL_Duplicate( p_this, p_acl ); vlc_acl_t *p_acl_new = ACL_Duplicate( p_this, *pp_acl );
lua_pushlightuserdata( L, p_acl_new ); return vlclua_acl_create_inner( L, p_acl_new );
return 1;
} }
int vlclua_acl_add_host( lua_State *L ) static int vlclua_acl_add_host( lua_State *L )
{ {
vlc_acl_t *p_acl = (vlc_acl_t*)luaL_checklightuserdata( L, 1 ); vlc_acl_t **pp_acl = (vlc_acl_t**)luaL_checkudata( L, 1, "acl" );
const char *psz_ip = luaL_checkstring( L, 2 ); const char *psz_ip = luaL_checkstring( L, 2 );
bool b_allow = luaL_checkboolean( L, 3 ) ? true : false; bool b_allow = luaL_checkboolean( L, 3 ) ? true : false;
lua_pushinteger( L, ACL_AddHost( p_acl, psz_ip, b_allow ) ); lua_pushinteger( L, ACL_AddHost( *pp_acl, psz_ip, b_allow ) );
return 1; return 1;
} }
int vlclua_acl_add_net( lua_State *L ) static int vlclua_acl_add_net( lua_State *L )
{ {
vlc_acl_t *p_acl = (vlc_acl_t*)luaL_checklightuserdata( L, 1 ); vlc_acl_t **pp_acl = (vlc_acl_t**)luaL_checkudata( L, 1, "acl" );
const char *psz_ip = luaL_checkstring( L, 2 ); const char *psz_ip = luaL_checkstring( L, 2 );
int i_len = luaL_checkint( L, 3 ); int i_len = luaL_checkint( L, 3 );
bool b_allow = luaL_checkboolean( L, 4 ) ? true : false; bool b_allow = luaL_checkboolean( L, 4 ) ? true : false;
lua_pushinteger( L, ACL_AddNet( p_acl, psz_ip, i_len, b_allow ) ); lua_pushinteger( L, ACL_AddNet( *pp_acl, psz_ip, i_len, b_allow ) );
return 1; return 1;
} }
int vlclua_acl_load_file( lua_State *L ) static int vlclua_acl_load_file( lua_State *L )
{ {
vlc_acl_t *p_acl = (vlc_acl_t*)luaL_checklightuserdata( L, 1 ); vlc_acl_t **pp_acl = (vlc_acl_t**)luaL_checkudata( L, 1, "acl" );
const char *psz_path = luaL_checkstring( L, 2 ); const char *psz_path = luaL_checkstring( L, 2 );
lua_pushinteger( L, ACL_LoadFile( p_acl, psz_path ) ); lua_pushinteger( L, ACL_LoadFile( *pp_acl, psz_path ) );
return 1; return 1;
} }
void luaopen_acl( lua_State *L )
{
lua_pushcfunction( L, vlclua_acl_create );
lua_setfield( L, -2, "acl" );
}
/***************************************************************************** /*****************************************************************************
* configuration.c: Generic lua<->vlc config interface * configuration.c: Generic lua<->vlc config interface
***************************************************************************** *****************************************************************************
* Copyright (C) 2007 the VideoLAN team * Copyright (C) 2007-2008 the VideoLAN team
* $Id$ * $Id$
* *
* Authors: Antoine Cellerier <dionoea at videolan tod org> * Authors: Antoine Cellerier <dionoea at videolan tod org>
...@@ -36,14 +36,14 @@ ...@@ -36,14 +36,14 @@
#include <lua.h> /* Low level lua C API */ #include <lua.h> /* Low level lua C API */
#include <lauxlib.h> /* Higher level C API */ #include <lauxlib.h> /* Higher level C API */
#include <lualib.h> /* Lua libs */
#include "vlc.h" #include "../vlc.h"
#include "../libs.h"
/***************************************************************************** /*****************************************************************************
* Config handling * Config handling
*****************************************************************************/ *****************************************************************************/
int vlclua_config_get( lua_State *L ) static int vlclua_config_get( lua_State *L )
{ {
vlc_object_t * p_this = vlclua_get_this( L ); vlc_object_t * p_this = vlclua_get_this( L );
const char *psz_name; const char *psz_name;
...@@ -76,7 +76,7 @@ int vlclua_config_get( lua_State *L ) ...@@ -76,7 +76,7 @@ int vlclua_config_get( lua_State *L )
return 1; return 1;
} }
int vlclua_config_set( lua_State *L ) static int vlclua_config_set( lua_State *L )
{ {
vlc_object_t *p_this = vlclua_get_this( L ); vlc_object_t *p_this = vlclua_get_this( L );
const char *psz_name; const char *psz_name;
...@@ -108,3 +108,19 @@ int vlclua_config_set( lua_State *L ) ...@@ -108,3 +108,19 @@ int vlclua_config_set( lua_State *L )
} }
return 0; return 0;
} }
/*****************************************************************************
*
*****************************************************************************/
static const luaL_Reg vlclua_config_reg[] = {
{ "get", vlclua_config_get },
{ "set", vlclua_config_set },
{ NULL, NULL }
};
void luaopen_config( lua_State *L )
{
lua_newtable( L );
luaL_register( L, NULL, vlclua_config_reg );
lua_setfield( L, -2, "config" );
}
/*****************************************************************************
* input.c
*****************************************************************************
* 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_meta.h>
#include <vlc_charset.h>
#include <vlc_playlist.h>
#include <lua.h> /* Low level lua C API */
#include <lauxlib.h> /* Higher level C API */
#include "input.h"
#include "playlist.h"
#include "../vlc.h"
#include "../libs.h"
input_thread_t * vlclua_get_input_internal( lua_State *L )
{
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
input_thread_t *p_input = p_playlist->p_input;
if( p_input ) vlc_object_yield( p_input );
vlc_object_release( p_playlist );
return p_input;
}
static int vlclua_input_info( lua_State *L )
{
input_thread_t * p_input = vlclua_get_input_internal( L );
int i_cat;
int i;
if( !p_input ) return vlclua_error( L );
//vlc_mutex_lock( &input_GetItem(p_input)->lock );
i_cat = input_GetItem(p_input)->i_categories;
lua_createtable( L, 0, i_cat );
for( i = 0; i < i_cat; i++ )
{
info_category_t *p_category = input_GetItem(p_input)->pp_categories[i];
int i_infos = p_category->i_infos;
int j;
lua_pushstring( L, p_category->psz_name );
lua_createtable( L, 0, i_infos );
for( j = 0; j < i_infos; j++ )
{
info_t *p_info = p_category->pp_infos[j];
lua_pushstring( L, p_info->psz_name );
lua_pushstring( L, p_info->psz_value );
lua_settable( L, -3 );
}
lua_settable( L, -3 );
}
//vlc_object_release( p_input );
return 1;
}
static int vlclua_is_playing( lua_State *L )
{
input_thread_t * p_input = vlclua_get_input_internal( L );
lua_pushboolean( L, !!p_input );
return 1;
}
static int vlclua_get_title( lua_State *L )
{
input_thread_t *p_input = vlclua_get_input_internal( L );
if( !p_input )
lua_pushnil( L );
else
{
lua_pushstring( L, input_GetItem(p_input)->psz_name );
vlc_object_release( p_input );
}
return 1;
}
static int vlclua_input_stats( lua_State *L )
{
input_thread_t *p_input = vlclua_get_input_internal( L );
input_item_t *p_item = p_input && p_input->p ? input_GetItem( p_input ) : NULL;
lua_newtable( L );
if( p_item )
{
#define STATS_INT( n ) lua_pushinteger( L, p_item->p_stats->i_ ## n ); \
lua_setfield( L, -2, #n );
#define STATS_FLOAT( n ) lua_pushnumber( L, p_item->p_stats->f_ ## n ); \
lua_setfield( L, -2, #n );
STATS_INT( read_bytes )
STATS_FLOAT( input_bitrate )
STATS_INT( demux_read_bytes )
STATS_FLOAT( demux_bitrate )
STATS_INT( decoded_video )
STATS_INT( displayed_pictures )
STATS_INT( lost_pictures )
STATS_INT( decoded_audio )
STATS_INT( played_abuffers )
STATS_INT( lost_abuffers )
STATS_INT( sent_packets )
STATS_INT( sent_bytes )
STATS_FLOAT( send_bitrate )
#undef STATS_INT
#undef STATS_FLOAT
}
return 1;
}
/*****************************************************************************
*
*****************************************************************************/
static const luaL_Reg vlclua_input_reg[] = {
{ "info", vlclua_input_info },
{ "is_playing", vlclua_is_playing },
{ "get_title", vlclua_get_title },
{ "stats", vlclua_input_stats },
{ NULL, NULL }
};
void luaopen_input( lua_State *L )
{
lua_newtable( L );
luaL_register( L, NULL, vlclua_input_reg );
lua_setfield( L, -2, "input" );
}
/*****************************************************************************
* input.h
*****************************************************************************
* 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.
*****************************************************************************/
#ifndef VLC_LUA_INPUT_H
#define VLC_LUA_INPUT_H
input_thread_t * vlclua_get_input_internal( lua_State * );
#endif
/*****************************************************************************
* messages.c
*****************************************************************************
* Copyright (C) 2007-2008 the VideoLAN team
* $Id$
*
* Authors: Antoine Cellerier <dionoea at videolan tod org>
* Pierre d'Herbemont <pdherbemont # videolan.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_plugin.h>
#include <vlc_meta.h>
#include <vlc_charset.h>
#include <vlc_aout.h>
#include <lua.h> /* Low level lua C API */
#include <lauxlib.h> /* Higher level C API */
#include <lualib.h> /* Lua libs */
#include "../vlc.h"
#include "../libs.h"
/*****************************************************************************
* Messaging facilities
*****************************************************************************/
static int vlclua_msg_dbg( lua_State *L )
{
int i_top = lua_gettop( L );
vlc_object_t *p_this = vlclua_get_this( L );
int i;
for( i = 1; i <= i_top; i++ )
msg_Dbg( p_this, "%s", luaL_checkstring( L, 1 ) );
return 0;
}
static int vlclua_msg_warn( lua_State *L )
{
int i_top = lua_gettop( L );
vlc_object_t *p_this = vlclua_get_this( L );
int i;
for( i = 1; i <= i_top; i++ )
msg_Warn( p_this, "%s", luaL_checkstring( L, i ) );
return 0;
}
static int vlclua_msg_err( lua_State *L )
{
int i_top = lua_gettop( L );
vlc_object_t *p_this = vlclua_get_this( L );
int i;
for( i = 1; i <= i_top; i++ )
msg_Err( p_this, "%s", luaL_checkstring( L, i ) );
return 0;
}
static int vlclua_msg_info( lua_State *L )
{
int i_top = lua_gettop( L );
vlc_object_t *p_this = vlclua_get_this( L );
int i;
for( i = 1; i <= i_top; i++ )
msg_Info( p_this, "%s", luaL_checkstring( L, i ) );
return 0;
}
/*****************************************************************************
*
*****************************************************************************/
static const luaL_Reg vlclua_msg_reg[] = {
{ "dbg", vlclua_msg_dbg },
{ "warn", vlclua_msg_warn },
{ "err", vlclua_msg_err },
{ "info", vlclua_msg_info },
{ NULL, NULL }
};
void luaopen_msg( lua_State *L )
{
lua_newtable( L );
luaL_register( L, NULL, vlclua_msg_reg );
lua_setfield( L, -2, "msg" );
}
/*****************************************************************************
* misc.c
*****************************************************************************
* Copyright (C) 2007-2008 the VideoLAN team
* $Id$
*
* Authors: Antoine Cellerier <dionoea at videolan tod org>
* Pierre d'Herbemont <pdherbemont # videolan.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_plugin.h>
#include <vlc_meta.h>
#include <vlc_charset.h>
#include <vlc_aout.h>
#include <vlc_interface.h>
#include <lua.h> /* Low level lua C API */
#include <lauxlib.h> /* Higher level C API */
#include <lualib.h> /* Lua libs */
#include "../vlc.h"
#include "../libs.h"
/*****************************************************************************
* Internal lua<->vlc utils
*****************************************************************************/
vlc_object_t * vlclua_get_this( lua_State *L )
{
vlc_object_t * p_this;
lua_getglobal( L, "vlc" );
lua_getfield( L, -1, "private" );
p_this = (vlc_object_t*)lua_topointer( L, lua_gettop( L ) );
lua_pop( L, 2 );
return p_this;
}
/*****************************************************************************
* VLC error code translation
*****************************************************************************/
int vlclua_push_ret( lua_State *L, int i_error )
{
lua_pushnumber( L, i_error );
lua_pushstring( L, vlc_error( i_error ) );
return 2;
}
/*****************************************************************************
* Get the VLC version string
*****************************************************************************/
static int vlclua_version( lua_State *L )
{
lua_pushstring( L, VLC_Version() );
return 1;
}
/*****************************************************************************
* Get the VLC copyright
*****************************************************************************/
static int vlclua_copyright( lua_State *L )
{
lua_pushstring( L, COPYRIGHT_MESSAGE );
return 1;
}
/*****************************************************************************
* Get the VLC license msg/disclaimer
*****************************************************************************/
static int vlclua_license( lua_State *L )
{
lua_pushstring( L, LICENSE_MSG );
return 1;
}
/*****************************************************************************
* Quit VLC
*****************************************************************************/
static int vlclua_quit( lua_State *L )
{
vlc_object_t *p_this = vlclua_get_this( L );
/* The rc.c code also stops the playlist ... not sure if this is needed
* though. */
vlc_object_kill( p_this->p_libvlc );
return 0;
}
/*****************************************************************************
* Global properties getters
*****************************************************************************/
static int vlclua_datadir( lua_State *L )
{
lua_pushstring( L, config_GetDataDir() );
return 1;
}
static int vlclua_homedir( lua_State *L )
{
lua_pushstring( L, config_GetHomeDir() );
return 1;
}
static int vlclua_configdir( lua_State *L )
{
char *dir = config_GetUserConfDir();
lua_pushstring( L, dir );
free( dir );
return 1;
}
static int vlclua_cachedir( lua_State *L )
{
char *dir = config_GetCacheDir();
lua_pushstring( L, dir );
free( dir );
return 1;
}
static int vlclua_datadir_list( lua_State *L )
{
const char *psz_dirname = luaL_checkstring( L, 1 );
char *ppsz_dir_list[] = { NULL, NULL, NULL, NULL };
char **ppsz_dir = ppsz_dir_list;
int i = 1;
if( vlclua_dir_list( psz_dirname, ppsz_dir_list ) != VLC_SUCCESS )
return 0;
lua_newtable( L );
for( ; *ppsz_dir; ppsz_dir++ )
{
lua_pushstring( L, *ppsz_dir );
lua_rawseti( L, -2, i );
i ++;
}
return 1;
}
/*****************************************************************************
*
*****************************************************************************/
static int vlclua_lock_and_wait( lua_State *L )
{
vlc_object_t *p_this = vlclua_get_this( L );
int b_quit = vlc_object_lock_and_wait( p_this );
lua_pushboolean( L, b_quit );
return 1;
}
static int vlclua_signal( lua_State *L )
{
vlc_object_t *p_this = vlclua_get_this( L );
vlc_object_signal( p_this );
return 0;
}
static int vlclua_mdate( lua_State *L )
{
lua_pushnumber( L, mdate() );
return 1;
}
static int vlclua_intf_should_die( lua_State *L )
{
intf_thread_t *p_intf = (intf_thread_t*)vlclua_get_this( L );
lua_pushboolean( L, intf_ShouldDie( p_intf ) );
return 1;
}
/*****************************************************************************
*
*****************************************************************************/
static const luaL_Reg vlclua_misc_reg[] = {
{ "version", vlclua_version },
{ "copyright", vlclua_copyright },
{ "license", vlclua_license },
{ "datadir", vlclua_datadir },
{ "homedir", vlclua_homedir },
{ "configdir", vlclua_configdir },
{ "cachedir", vlclua_cachedir },
{ "datadir_list", vlclua_datadir_list },
{ "mdate", vlclua_mdate },
{ "lock_and_wait", vlclua_lock_and_wait },
{ "signal", vlclua_signal },
{ "should_die", vlclua_intf_should_die },
{ "quit", vlclua_quit },
{ NULL, NULL }
};
void luaopen_misc( lua_State *L )
{
lua_newtable( L );
luaL_register( L, NULL, vlclua_misc_reg );
lua_setfield( L, -2, "misc" );
}
/*****************************************************************************
* misc.h
*****************************************************************************
* Copyright (C) 2007-2008 the VideoLAN team
* $Id$
*
* Authors: Antoine Cellerier <dionoea at videolan tod org>
* Pierre d'Herbemont <pdherbemont # videolan.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.
*****************************************************************************/
#ifndef VLC_LUA_MISC_H
#define VLC_LUA_MISC_H
vlc_object_t * vlclua_get_this( lua_State * );
int vlclua_push_ret( lua_State *, int );
#endif
/***************************************************************************** /*****************************************************************************
* net.c: Network related functions * net.c: Network related functions
***************************************************************************** *****************************************************************************
* Copyright (C) 2007 the VideoLAN team * Copyright (C) 2007-2008 the VideoLAN team
* $Id$ * $Id$
* *
* Authors: Antoine Cellerier <dionoea at videolan tod org> * Authors: Antoine Cellerier <dionoea at videolan tod org>
...@@ -38,14 +38,14 @@ ...@@ -38,14 +38,14 @@
#include <lua.h> /* Low level lua C API */ #include <lua.h> /* Low level lua C API */
#include <lauxlib.h> /* Higher level C API */ #include <lauxlib.h> /* Higher level C API */
#include <lualib.h> /* Lua libs */
#include "vlc.h" #include "../vlc.h"
#include "../libs.h"
/***************************************************************************** /*****************************************************************************
* *
*****************************************************************************/ *****************************************************************************/
int vlclua_url_parse( lua_State *L ) static int vlclua_url_parse( lua_State *L )
{ {
const char *psz_url = luaL_checkstring( L, 1 ); const char *psz_url = luaL_checkstring( L, 1 );
const char *psz_option = luaL_optstring( L, 2, NULL ); const char *psz_option = luaL_optstring( L, 2, NULL );
...@@ -74,7 +74,18 @@ int vlclua_url_parse( lua_State *L ) ...@@ -74,7 +74,18 @@ int vlclua_url_parse( lua_State *L )
return 1; return 1;
} }
int vlclua_net_listen_tcp( lua_State *L ) /*****************************************************************************
* Net listen
*****************************************************************************/
static int vlclua_net_listen_close( lua_State * );
static int vlclua_net_accept( lua_State * );
static const luaL_Reg vlclua_net_listen_reg[] = {
{ "accept", vlclua_net_accept },
{ NULL, NULL }
};
static int vlclua_net_listen_tcp( lua_State *L )
{ {
vlc_object_t *p_this = vlclua_get_this( L ); vlc_object_t *p_this = vlclua_get_this( L );
const char *psz_host = luaL_checkstring( L, 1 ); const char *psz_host = luaL_checkstring( L, 1 );
...@@ -82,35 +93,51 @@ int vlclua_net_listen_tcp( lua_State *L ) ...@@ -82,35 +93,51 @@ int vlclua_net_listen_tcp( lua_State *L )
int *pi_fd = net_ListenTCP( p_this, psz_host, i_port ); int *pi_fd = net_ListenTCP( p_this, psz_host, i_port );
if( pi_fd == NULL ) if( pi_fd == NULL )
return luaL_error( L, "Cannot listen on %s:%d", psz_host, i_port ); return luaL_error( L, "Cannot listen on %s:%d", psz_host, i_port );
lua_pushlightuserdata( L, pi_fd );
int **ppi_fd = lua_newuserdata( L, sizeof( int * ) );
*ppi_fd = pi_fd;
if( luaL_newmetatable( L, "net_listen" ) )
{
lua_newtable( L );
luaL_register( L, NULL, vlclua_net_listen_reg );
lua_setfield( L, -2, "__index" );
lua_pushcfunction( L, vlclua_net_listen_close );
lua_setfield( L, -2, "__gc" );
}
lua_setmetatable( L, -2 );
return 1; return 1;
} }
int vlclua_net_listen_close( lua_State *L ) static int vlclua_net_listen_close( lua_State *L )
{ {
int *pi_fd = (int*)luaL_checklightuserdata( L, 1 ); int **ppi_fd = (int**)luaL_checkudata( L, 1, "net_listen" );
net_ListenClose( pi_fd ); net_ListenClose( *ppi_fd );
return 0; return 0;
} }
int vlclua_net_accept( lua_State *L ) static int vlclua_net_accept( lua_State *L )
{ {
vlc_object_t *p_this = vlclua_get_this( L ); vlc_object_t *p_this = vlclua_get_this( L );
int *pi_fd = (int*)luaL_checklightuserdata( L, 1 ); int **ppi_fd = (int**)luaL_checkudata( L, 1, "net_listen" );
mtime_t i_wait = luaL_optint( L, 2, -1 ); /* default to block */ mtime_t i_wait = luaL_optint( L, 2, -1 ); /* default to block */
int i_fd = net_Accept( p_this, pi_fd, i_wait ); int i_fd = net_Accept( p_this, *ppi_fd, i_wait );
lua_pushinteger( L, i_fd ); lua_pushinteger( L, i_fd );
return 1; return 1;
} }
int vlclua_net_close( lua_State *L ) /*****************************************************************************
*
*****************************************************************************/
static int vlclua_net_close( lua_State *L )
{ {
int i_fd = luaL_checkint( L, 1 ); int i_fd = luaL_checkint( L, 1 );
net_Close( i_fd ); net_Close( i_fd );
return 0; return 0;
} }
int vlclua_net_send( lua_State *L ) static int vlclua_net_send( lua_State *L )
{ {
int i_fd = luaL_checkint( L, 1 ); int i_fd = luaL_checkint( L, 1 );
size_t i_len; size_t i_len;
...@@ -121,7 +148,7 @@ int vlclua_net_send( lua_State *L ) ...@@ -121,7 +148,7 @@ int vlclua_net_send( lua_State *L )
return 1; return 1;
} }
int vlclua_net_recv( lua_State *L ) static int vlclua_net_recv( lua_State *L )
{ {
int i_fd = luaL_checkint( L, 1 ); int i_fd = luaL_checkint( L, 1 );
size_t i_len = luaL_optint( L, 2, 1 ); size_t i_len = luaL_optint( L, 2, 1 );
...@@ -131,12 +158,15 @@ int vlclua_net_recv( lua_State *L ) ...@@ -131,12 +158,15 @@ int vlclua_net_recv( lua_State *L )
return 1; return 1;
} }
int vlclua_net_select( lua_State *L ) /*****************************************************************************
*
*****************************************************************************/
static int vlclua_net_select( lua_State *L )
{ {
int i_ret; int i_ret;
size_t i_nfds = luaL_checkint( L, 1 ); size_t i_nfds = luaL_checkint( L, 1 );
fd_set *fds_read = (fd_set*)luaL_checkuserdata( L, 2, sizeof( fd_set ) ); fd_set *fds_read = (fd_set*)luaL_checkudata( L, 2, "fd_set" );
fd_set *fds_write = (fd_set*)luaL_checkuserdata( L, 3, sizeof( fd_set ) ); fd_set *fds_write = (fd_set*)luaL_checkudata( L, 3, "fd_set" );
double f_timeout = luaL_checknumber( L, 4 ); double f_timeout = luaL_checknumber( L, 4 );
struct timeval timeout; struct timeval timeout;
...@@ -152,30 +182,57 @@ int vlclua_net_select( lua_State *L ) ...@@ -152,30 +182,57 @@ int vlclua_net_select( lua_State *L )
return 2; return 2;
} }
int vlclua_fd_set_new( lua_State *L ) /*****************************************************************************
*
*****************************************************************************/
static int vlclua_fd_clr( lua_State * );
static int vlclua_fd_isset( lua_State * );
static int vlclua_fd_set( lua_State * );
static int vlclua_fd_zero( lua_State * );
static const luaL_Reg vlclua_fd_set_reg[] = {
{ "clr", vlclua_fd_clr },
{ "isset", vlclua_fd_isset },
{ "set", vlclua_fd_set },
{ "zero", vlclua_fd_zero },
{ NULL, NULL }
};
static int vlclua_fd_set_new( lua_State *L )
{ {
fd_set *fds = (fd_set*)lua_newuserdata( L, sizeof( fd_set ) ); fd_set *fds = (fd_set*)lua_newuserdata( L, sizeof( fd_set ) );
FD_ZERO( fds ); FD_ZERO( fds );
if( luaL_newmetatable( L, "fd_set" ) )
{
lua_newtable( L );
luaL_register( L, NULL, vlclua_fd_set_reg );
lua_setfield( L, -2, "__index" );
}
lua_setmetatable( L, -2 );
return 1; return 1;
} }
int vlclua_fd_clr( lua_State *L ) static int vlclua_fd_clr( lua_State *L )
{ {
fd_set *fds = (fd_set*)luaL_checkuserdata( L, 1, sizeof( fd_set ) ); fd_set *fds = (fd_set*)luaL_checkudata( L, 1, "fd_set" );
int i_fd = luaL_checkint( L, 2 ); int i_fd = luaL_checkint( L, 2 );
FD_CLR( i_fd, fds ); FD_CLR( i_fd, fds );
return 0; return 0;
} }
int vlclua_fd_isset( lua_State *L )
static int vlclua_fd_isset( lua_State *L )
{ {
fd_set *fds = (fd_set*)luaL_checkuserdata( L, 1, sizeof( fd_set ) ); fd_set *fds = (fd_set*)luaL_checkudata( L, 1, "fd_set" );
int i_fd = luaL_checkint( L, 2 ); int i_fd = luaL_checkint( L, 2 );
lua_pushboolean( L, FD_ISSET( i_fd, fds ) ); lua_pushboolean( L, FD_ISSET( i_fd, fds ) );
return 1; return 1;
} }
int vlclua_fd_set( lua_State *L )
static int vlclua_fd_set( lua_State *L )
{ {
fd_set *fds = (fd_set*)luaL_checkuserdata( L, 1, sizeof( fd_set ) ); fd_set *fds = (fd_set*)luaL_checkudata( L, 1, "fd_set" );
size_t i_fd = luaL_checkint( L, 2 ); size_t i_fd = luaL_checkint( L, 2 );
/* FIXME: we should really use poll() instead here, but that breaks the /* FIXME: we should really use poll() instead here, but that breaks the
* VLC/LUA API. On Windows, overflow protection is built-in FD_SET, not * VLC/LUA API. On Windows, overflow protection is built-in FD_SET, not
...@@ -186,20 +243,24 @@ int vlclua_fd_set( lua_State *L ) ...@@ -186,20 +243,24 @@ int vlclua_fd_set( lua_State *L )
FD_SET( i_fd, fds ); FD_SET( i_fd, fds );
return 0; return 0;
} }
int vlclua_fd_zero( lua_State *L )
static int vlclua_fd_zero( lua_State *L )
{ {
fd_set *fds = (fd_set*)luaL_checkuserdata( L, 1, sizeof( fd_set ) ); fd_set *fds = (fd_set*)luaL_checkudata( L, 1, "fd_set" );
FD_ZERO( fds ); FD_ZERO( fds );
return 0; return 0;
} }
/*****************************************************************************
*
*****************************************************************************/
/* /*
int vlclua_fd_open( lua_State *L ) static int vlclua_fd_open( lua_State *L )
{ {
} }
*/ */
int vlclua_fd_write( lua_State *L ) static int vlclua_fd_write( lua_State *L )
{ {
int i_fd = luaL_checkint( L, 1 ); int i_fd = luaL_checkint( L, 1 );
size_t i_len; size_t i_len;
...@@ -211,7 +272,7 @@ int vlclua_fd_write( lua_State *L ) ...@@ -211,7 +272,7 @@ int vlclua_fd_write( lua_State *L )
return 1; return 1;
} }
int vlclua_fd_read( lua_State *L ) static int vlclua_fd_read( lua_State *L )
{ {
int i_fd = luaL_checkint( L, 1 ); int i_fd = luaL_checkint( L, 1 );
size_t i_len = luaL_optint( L, 2, 1 ); size_t i_len = luaL_optint( L, 2, 1 );
...@@ -221,7 +282,10 @@ int vlclua_fd_read( lua_State *L ) ...@@ -221,7 +282,10 @@ int vlclua_fd_read( lua_State *L )
return 1; return 1;
} }
int vlclua_stat( lua_State *L ) /*****************************************************************************
*
*****************************************************************************/
static int vlclua_stat( lua_State *L )
{ {
#ifdef HAVE_SYS_STAT_H #ifdef HAVE_SYS_STAT_H
const char *psz_path = luaL_checkstring( L, 1 ); const char *psz_path = luaL_checkstring( L, 1 );
...@@ -278,7 +342,7 @@ int vlclua_stat( lua_State *L ) ...@@ -278,7 +342,7 @@ int vlclua_stat( lua_State *L )
#endif #endif
} }
int vlclua_opendir( lua_State *L ) static int vlclua_opendir( lua_State *L )
{ {
const char *psz_dir = luaL_checkstring( L, 1 ); const char *psz_dir = luaL_checkstring( L, 1 );
DIR *p_dir; DIR *p_dir;
...@@ -300,3 +364,28 @@ int vlclua_opendir( lua_State *L ) ...@@ -300,3 +364,28 @@ int vlclua_opendir( lua_State *L )
closedir( p_dir ); closedir( p_dir );
return 1; return 1;
} }
/*****************************************************************************
*
*****************************************************************************/
static const luaL_Reg vlclua_net_reg[] = {
{ "url_parse", vlclua_url_parse },
{ "listen_tcp", vlclua_net_listen_tcp },
{ "close", vlclua_net_close },
{ "send", vlclua_net_send },
{ "recv", vlclua_net_recv },
{ "select", vlclua_net_select },
{ "fd_set_new", vlclua_fd_set_new },
{ "fd_read", vlclua_fd_read },
{ "fd_write", vlclua_fd_write },
{ "stat", vlclua_stat }, /* Not really "net" */
{ "opendir", vlclua_opendir }, /* Not really "net" */
{ NULL, NULL }
};
void luaopen_net( lua_State *L )
{
lua_newtable( L );
luaL_register( L, NULL, vlclua_net_reg );
lua_setfield( L, -2, "net" );
}
/***************************************************************************** /*****************************************************************************
* objects.c: Generic lua<->vlc object wrapper * objects.c: Generic lua<->vlc object wrapper
***************************************************************************** *****************************************************************************
* Copyright (C) 2007 the VideoLAN team * Copyright (C) 2007-2008 the VideoLAN team
* $Id$ * $Id$
* *
* Authors: Antoine Cellerier <dionoea at videolan tod org> * Authors: Antoine Cellerier <dionoea at videolan tod org>
...@@ -36,9 +36,12 @@ ...@@ -36,9 +36,12 @@
#include <lua.h> /* Low level lua C API */ #include <lua.h> /* Low level lua C API */
#include <lauxlib.h> /* Higher level C API */ #include <lauxlib.h> /* Higher level C API */
#include <lualib.h> /* Lua libs */
#include "vlc.h" #include "../vlc.h"
#include "../libs.h"
#include "objects.h"
#include "playlist.h"
#include "input.h"
typedef struct typedef struct
{ {
...@@ -51,20 +54,21 @@ typedef struct ...@@ -51,20 +54,21 @@ typedef struct
int __vlclua_push_vlc_object( lua_State *L, vlc_object_t *p_obj, int __vlclua_push_vlc_object( lua_State *L, vlc_object_t *p_obj,
lua_CFunction pf_gc ) lua_CFunction pf_gc )
{ {
vlclua_object_t *p_ud = (vlclua_object_t *) vlc_object_t **udata = (vlc_object_t **)
lua_newuserdata( L, sizeof( vlclua_object_t ) ); lua_newuserdata( L, sizeof( vlc_object_t * ) );
p_ud->p_obj = p_obj; *udata = p_obj;
lua_newtable( L );
/* Hide the metatable */ if( luaL_newmetatable( L, "vlc_object" ) )
lua_pushstring( L, "__metatable" );
lua_pushstring( L, "none of your business" );
lua_settable( L, -3 );
if( pf_gc )
{ {
/* Set the garbage collector if needed */ /* Hide the metatable */
lua_pushstring( L, "__gc" ); lua_pushstring( L, "none of your business" );
lua_pushcfunction( L, pf_gc ); lua_setfield( L, -2, "__metatable" );
lua_settable( L, -3 ); if( pf_gc ) /* FIXME */
{
/* Set the garbage collector if needed */
lua_pushcfunction( L, pf_gc );
lua_setfield( L, -2, "__gc" );
}
} }
lua_setmetatable( L, -2 ); lua_setmetatable( L, -2 );
return 1; return 1;
...@@ -72,34 +76,12 @@ int __vlclua_push_vlc_object( lua_State *L, vlc_object_t *p_obj, ...@@ -72,34 +76,12 @@ int __vlclua_push_vlc_object( lua_State *L, vlc_object_t *p_obj,
int vlclua_gc_release( lua_State *L ) int vlclua_gc_release( lua_State *L )
{ {
vlclua_object_t *p_ud = (vlclua_object_t *)lua_touserdata( L, -1 ); vlc_object_t **p_obj = (vlc_object_t **)luaL_checkudata( L, 1, "vlc_object" );
lua_pop( L, 1 ); lua_pop( L, 1 );
vlc_object_release( p_ud->p_obj ); vlc_object_release( *p_obj );
return 0; return 0;
} }
vlc_object_t *vlclua_checkobject( lua_State *L, int narg, int i_type )
{
vlclua_object_t *p_obj = (vlclua_object_t *)luaL_checkuserdata( L, narg, sizeof( vlclua_object_t ) );
/* TODO: add some metatable based method to check that this isn't
* any userdata, but really some vlc object */
if( i_type )
{
if( p_obj->p_obj->i_object_type == i_type )
return p_obj->p_obj;
else
{
luaL_error( L, "VLC object type doesn't match requirements." );
return NULL; /* luaL_error alread longjmp-ed out of here.
* This is to make gcc happy */
}
}
else
{
return p_obj->p_obj;
}
}
static int vlc_object_type_from_string( const char *psz_name ) static int vlc_object_type_from_string( const char *psz_name )
{ {
static const struct static const struct
...@@ -125,6 +107,7 @@ static int vlc_object_type_from_string( const char *psz_name ) ...@@ -125,6 +107,7 @@ static int vlc_object_type_from_string( const char *psz_name )
{ VLC_OBJECT_FILTER, "filter" }, { VLC_OBJECT_FILTER, "filter" },
{ VLC_OBJECT_OSDMENU, "osdmenu" }, { VLC_OBJECT_OSDMENU, "osdmenu" },
{ VLC_OBJECT_HTTPD_HOST, "httpd_host" }, { VLC_OBJECT_HTTPD_HOST, "httpd_host" },
{ VLC_OBJECT_INTERACTION, "interaction" },
{ VLC_OBJECT_GENERIC, "generic" }, { VLC_OBJECT_GENERIC, "generic" },
{ 0, "" } }; { 0, "" } };
int i; int i;
...@@ -156,7 +139,7 @@ static int vlc_object_search_mode_from_string( const char *psz_name ) ...@@ -156,7 +139,7 @@ static int vlc_object_search_mode_from_string( const char *psz_name )
return 0; return 0;
} }
int vlclua_object_find( lua_State *L ) static int vlclua_object_find( lua_State *L )
{ {
const char *psz_type = luaL_checkstring( L, 2 ); const char *psz_type = luaL_checkstring( L, 2 );
const char *psz_mode = luaL_checkstring( L, 3 ); const char *psz_mode = luaL_checkstring( L, 3 );
...@@ -174,7 +157,10 @@ int vlclua_object_find( lua_State *L ) ...@@ -174,7 +157,10 @@ int vlclua_object_find( lua_State *L )
if( lua_type( L, 1 ) == LUA_TNIL ) if( lua_type( L, 1 ) == LUA_TNIL )
p_this = vlclua_get_this( L ); p_this = vlclua_get_this( L );
else else
p_this = vlclua_checkobject( L, 1, 0 ); {
vlc_object_t **p_obj = luaL_checkudata( L, 1, "vlc_object" );
p_this = *p_obj;
}
p_result = vlc_object_find( p_this, i_type, i_mode ); p_result = vlc_object_find( p_this, i_type, i_mode );
if( !p_result ) if( !p_result )
...@@ -184,7 +170,7 @@ int vlclua_object_find( lua_State *L ) ...@@ -184,7 +170,7 @@ int vlclua_object_find( lua_State *L )
return 1; return 1;
} }
int vlclua_object_find_name( lua_State *L ) static int vlclua_object_find_name( lua_State *L )
{ {
const char *psz_name = luaL_checkstring( L, 2 ); const char *psz_name = luaL_checkstring( L, 2 );
const char *psz_mode = luaL_checkstring( L, 3 ); const char *psz_mode = luaL_checkstring( L, 3 );
...@@ -200,7 +186,10 @@ int vlclua_object_find_name( lua_State *L ) ...@@ -200,7 +186,10 @@ int vlclua_object_find_name( lua_State *L )
if( lua_type( L, 1 ) == LUA_TNIL ) if( lua_type( L, 1 ) == LUA_TNIL )
p_this = vlclua_get_this( L ); p_this = vlclua_get_this( L );
else else
p_this = vlclua_checkobject( L, 1, 0 ); {
vlc_object_t **p_obj = luaL_checkudata( L, 1, "vlc_object" );
p_this = *p_obj;
}
p_result = vlc_object_find_name( p_this, psz_name, i_mode ); p_result = vlc_object_find_name( p_this, psz_name, i_mode );
if( !p_result ) if( !p_result )
...@@ -209,3 +198,51 @@ int vlclua_object_find_name( lua_State *L ) ...@@ -209,3 +198,51 @@ int vlclua_object_find_name( lua_State *L )
vlclua_push_vlc_object( L, p_result, vlclua_gc_release ); vlclua_push_vlc_object( L, p_result, vlclua_gc_release );
return 1; return 1;
} }
static int vlclua_get_libvlc( lua_State *L )
{
vlclua_push_vlc_object( L, vlclua_get_this( L )->p_libvlc,
NULL );
return 1;
}
static int vlclua_get_playlist( lua_State *L )
{
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
if( p_playlist )
{
vlclua_push_vlc_object( L, p_playlist, vlclua_gc_release );
}
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 )
{
vlclua_push_vlc_object( L, p_input, vlclua_gc_release );
}
else 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 },
{ "find_name", vlclua_object_find_name },
{ NULL, NULL }
};
void luaopen_object( lua_State *L )
{
lua_newtable( L );
luaL_register( L, NULL, vlclua_object_reg );
lua_setfield( L, -2, "object" );
}
/*****************************************************************************
* objects.c: Generic lua<->vlc object wrapper
*****************************************************************************
* Copyright (C) 2007-2008 the VideoLAN team
* $Id$
*
* Authors: Antoine Cellerier <dionoea at videolan tod org>
* Pierre d'Herbemont <pdherbemont # videolan.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.
*****************************************************************************/
#ifndef VLC_LUA_OBJECTS_H
#define VLC_LUA_OBJECTS_H
int __vlclua_push_vlc_object( lua_State *L, vlc_object_t *p_obj,
lua_CFunction pf_gc );
#define vlclua_push_vlc_object( a, b, c ) \
__vlclua_push_vlc_object( a, VLC_OBJECT( b ), c )
int vlclua_gc_release( lua_State *L );
#endif
/*****************************************************************************
* intf.c: Generic lua interface functions
*****************************************************************************
* 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_vout.h>
#include <vlc_osd.h>
#include <lua.h> /* Low level lua C API */
#include <lauxlib.h> /* Higher level C API */
#include "../vlc.h"
#include "../libs.h"
/*****************************************************************************
* OSD
*****************************************************************************/
static int vlc_osd_icon_from_string( const char *psz_name )
{
static const struct
{
int i_icon;
const char *psz_name;
} pp_icons[] =
{ { OSD_PAUSE_ICON, "pause" },
{ OSD_PLAY_ICON, "play" },
{ OSD_SPEAKER_ICON, "speaker" },
{ OSD_MUTE_ICON, "mute" },
{ 0, NULL } };
int i;
for( i = 0; pp_icons[i].psz_name; i++ )
{
if( !strcmp( psz_name, pp_icons[i].psz_name ) )
return pp_icons[i].i_icon;
}
return 0;
}
static int vlclua_osd_icon( lua_State *L )
{
const char *psz_icon = luaL_checkstring( L, 1 );
int i_icon = vlc_osd_icon_from_string( psz_icon );
int i_chan = luaL_optint( L, 2, DEFAULT_CHAN );
if( !i_icon )
return luaL_error( L, "\"%s\" is not a valid osd icon.", psz_icon );
else
{
vlc_object_t *p_this = vlclua_get_this( L );
vout_OSDIcon( p_this, i_chan, i_icon );
return 0;
}
}
static int vlclua_osd_message( lua_State *L )
{
const char *psz_message = luaL_checkstring( L, 1 );
int i_chan = luaL_optint( L, 2, DEFAULT_CHAN );
vlc_object_t *p_this = vlclua_get_this( L );
vout_OSDMessage( p_this, i_chan, psz_message );
return 0;
}
static int vlc_osd_slider_type_from_string( const char *psz_name )
{
static const struct
{
int i_type;
const char *psz_name;
} pp_types[] =
{ { OSD_HOR_SLIDER, "horizontal" },
{ OSD_VERT_SLIDER, "vertical" },
{ 0, NULL } };
int i;
for( i = 0; pp_types[i].psz_name; i++ )
{
if( !strcmp( psz_name, pp_types[i].psz_name ) )
return pp_types[i].i_type;
}
return 0;
}
static int vlclua_osd_slider( lua_State *L )
{
int i_position = luaL_checkint( L, 1 );
const char *psz_type = luaL_checkstring( L, 2 );
int i_type = vlc_osd_slider_type_from_string( psz_type );
int i_chan = luaL_optint( L, 3, DEFAULT_CHAN );
if( !i_type )
return luaL_error( L, "\"%s\" is not a valid slider type.",
psz_type );
else
{
vlc_object_t *p_this = vlclua_get_this( L );
vout_OSDSlider( p_this, i_chan, i_position, i_type );
return 0;
}
}
static int vlclua_spu_channel_register( lua_State *L )
{
int i_chan;
vlc_object_t *p_this = vlclua_get_this( L );
vout_thread_t *p_vout = vlc_object_find( p_this, VLC_OBJECT_VOUT,
FIND_ANYWHERE );
if( !p_vout )
return luaL_error( L, "Unable to find vout." );
spu_Control( p_vout->p_spu, SPU_CHANNEL_REGISTER, &i_chan );
vlc_object_release( p_vout );
lua_pushinteger( L, i_chan );
return 1;
}
static int vlclua_spu_channel_clear( lua_State *L )
{
int i_chan = luaL_checkint( L, 1 );
vlc_object_t *p_this = vlclua_get_this( L );
vout_thread_t *p_vout = vlc_object_find( p_this, VLC_OBJECT_VOUT,
FIND_ANYWHERE );
if( !p_vout )
return luaL_error( L, "Unable to find vout." );
spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR, i_chan );
vlc_object_release( p_vout );
return 0;
}
/*****************************************************************************
*
*****************************************************************************/
static const luaL_Reg vlclua_osd_reg[] = {
{ "icon", vlclua_osd_icon },
{ "message", vlclua_osd_message },
{ "slider", vlclua_osd_slider },
{ "channel_register", vlclua_spu_channel_register },
{ "channel_clear", vlclua_spu_channel_clear },
{ NULL, NULL }
};
void luaopen_osd( lua_State *L )
{
lua_newtable( L );
luaL_register( L, NULL, vlclua_osd_reg );
lua_setfield( L, -2, "osd" );
}
This diff is collapsed.
/*****************************************************************************
* playlist.h
*****************************************************************************
* 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.
*****************************************************************************/
#ifndef VLC_LUA_PLAYLIST_H
#define VLC_LUA_PLAYLIST_H
playlist_t *vlclua_get_playlist_internal( lua_State * );
#endif
/***************************************************************************** /*****************************************************************************
* sd.c: Services discovery related functions * sd.c: Services discovery related functions
***************************************************************************** *****************************************************************************
* Copyright (C) 2007 the VideoLAN team * Copyright (C) 2007-2008 the VideoLAN team
* $Id$ * $Id$
* *
* Authors: Antoine Cellerier <dionoea at videolan tod org> * Authors: Antoine Cellerier <dionoea at videolan tod org>
...@@ -40,12 +40,14 @@ ...@@ -40,12 +40,14 @@
#include <lauxlib.h> /* Higher level C API */ #include <lauxlib.h> /* Higher level C API */
#include <lualib.h> /* Lua libs */ #include <lualib.h> /* Lua libs */
#include "vlc.h" #include "../vlc.h"
#include "../libs.h"
#include "playlist.h"
/***************************************************************************** /*****************************************************************************
* *
*****************************************************************************/ *****************************************************************************/
int vlclua_sd_get_services_names( lua_State *L ) static int vlclua_sd_get_services_names( lua_State *L )
{ {
vlc_object_t *p_this = vlclua_get_this( L ); vlc_object_t *p_this = vlclua_get_this( L );
char **ppsz_longnames; char **ppsz_longnames;
...@@ -69,7 +71,7 @@ int vlclua_sd_get_services_names( lua_State *L ) ...@@ -69,7 +71,7 @@ int vlclua_sd_get_services_names( lua_State *L )
return 1; return 1;
} }
int vlclua_sd_add( lua_State *L ) static int vlclua_sd_add( lua_State *L )
{ {
const char *psz_sd = luaL_checkstring( L, 1 ); const char *psz_sd = luaL_checkstring( L, 1 );
playlist_t *p_playlist = vlclua_get_playlist_internal( L ); playlist_t *p_playlist = vlclua_get_playlist_internal( L );
...@@ -78,7 +80,7 @@ int vlclua_sd_add( lua_State *L ) ...@@ -78,7 +80,7 @@ int vlclua_sd_add( lua_State *L )
return vlclua_push_ret( L, i_ret ); return vlclua_push_ret( L, i_ret );
} }
int vlclua_sd_remove( lua_State *L ) static int vlclua_sd_remove( lua_State *L )
{ {
const char *psz_sd = luaL_checkstring( L, 1 ); const char *psz_sd = luaL_checkstring( L, 1 );
playlist_t *p_playlist = vlclua_get_playlist_internal( L ); playlist_t *p_playlist = vlclua_get_playlist_internal( L );
...@@ -87,7 +89,7 @@ int vlclua_sd_remove( lua_State *L ) ...@@ -87,7 +89,7 @@ int vlclua_sd_remove( lua_State *L )
return vlclua_push_ret( L, i_ret ); return vlclua_push_ret( L, i_ret );
} }
int vlclua_sd_is_loaded( lua_State *L ) static int vlclua_sd_is_loaded( lua_State *L )
{ {
const char *psz_sd = luaL_checkstring( L, 1 ); const char *psz_sd = luaL_checkstring( L, 1 );
playlist_t *p_playlist = vlclua_get_playlist_internal( L ); playlist_t *p_playlist = vlclua_get_playlist_internal( L );
...@@ -95,3 +97,21 @@ int vlclua_sd_is_loaded( lua_State *L ) ...@@ -95,3 +97,21 @@ int vlclua_sd_is_loaded( lua_State *L )
vlc_object_release( p_playlist ); vlc_object_release( p_playlist );
return 1; return 1;
} }
/*****************************************************************************
*
*****************************************************************************/
static const luaL_Reg vlclua_sd_reg[] = {
{ "get_services_names", vlclua_sd_get_services_names },
{ "add", vlclua_sd_add },
{ "remove", vlclua_sd_remove },
{ "is_loaded", vlclua_sd_is_loaded },
{ NULL, NULL }
};
void luaopen_sd( lua_State *L )
{
lua_newtable( L );
luaL_register( L, NULL, vlclua_sd_reg );
lua_setfield( L, -2, "sd" );
}
/*****************************************************************************
* stream.c: stream functions
*****************************************************************************
* Copyright (C) 2007-2008 the VideoLAN team
* $Id$
*
* Authors: Antoine Cellerier <dionoea at videolan tod org>
* Pierre d'Herbemont <pdherbemont # videolan.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_plugin.h>
#include <vlc_meta.h>
#include <vlc_charset.h>
#include <vlc_aout.h>
#include <lua.h> /* Low level lua C API */
#include <lauxlib.h> /* Higher level C API */
#include "../vlc.h"
#include "../libs.h"
/*****************************************************************************
* Stream handling
*****************************************************************************/
static int vlclua_stream_read( lua_State * );
static int vlclua_stream_readline( lua_State * );
static int vlclua_stream_delete( lua_State * );
static const luaL_Reg vlclua_stream_reg[] = {
{ "read", vlclua_stream_read },
{ "readline", vlclua_stream_readline },
{ NULL, NULL }
};
static int vlclua_stream_new( lua_State *L )
{
vlc_object_t * p_this = vlclua_get_this( L );
stream_t * p_stream;
const char * psz_url;
psz_url = luaL_checkstring( L, -1 );
p_stream = stream_UrlNew( p_this, psz_url );
if( !p_stream )
return luaL_error( L, "Error when opening url: `%s'", psz_url );
stream_t **pp_stream = lua_newuserdata( L, sizeof( stream_t * ) );
*pp_stream = p_stream;
if( luaL_newmetatable( L, "stream" ) )
{
lua_newtable( L );
luaL_register( L, NULL, vlclua_stream_reg );
lua_setfield( L, -2, "__index" );
lua_pushcfunction( L, vlclua_stream_delete );
lua_setfield( L, -2, "__gc" );
}
lua_setmetatable( L, -2 );
return 1;
}
static int vlclua_stream_read( lua_State *L )
{
int i_read;
stream_t **pp_stream = (stream_t **)luaL_checkudata( L, 1, "stream" );
int n = luaL_checkint( L, 2 );
uint8_t *p_read = malloc( n );
if( !p_read ) return vlclua_error( L );
i_read = stream_Read( *pp_stream, p_read, n );
lua_pushlstring( L, (const char *)p_read, i_read );
free( p_read );
return 1;
}
static int vlclua_stream_readline( lua_State *L )
{
stream_t **pp_stream = (stream_t **)luaL_checkudata( L, 1, "stream" );
char *psz_line = stream_ReadLine( *pp_stream );
if( psz_line )
{
lua_pushstring( L, psz_line );
free( psz_line );
}
else
lua_pushnil( L );
return 1;
}
static int vlclua_stream_delete( lua_State *L )
{
stream_t **pp_stream = (stream_t **)luaL_checkudata( L, 1, "stream" );
stream_Delete( *pp_stream );
return 0;
}
/*****************************************************************************
*
*****************************************************************************/
void luaopen_stream( lua_State *L )
{
lua_pushcfunction( L, vlclua_stream_new );
lua_setfield( L, -2, "stream" );
}
/*****************************************************************************
* strings.c
*****************************************************************************
* Copyright (C) 2007-2008 the VideoLAN team
* $Id$
*
* Authors: Antoine Cellerier <dionoea at videolan tod org>
* Pierre d'Herbemont <pdherbemont # videolan.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_plugin.h>
#include <vlc_meta.h>
#include <vlc_charset.h>
#include <vlc_aout.h>
#include <lua.h> /* Low level lua C API */
#include <lauxlib.h> /* Higher level C API */
#include "../vlc.h"
#include "../libs.h"
/*****************************************************************************
* String transformations
*****************************************************************************/
static int vlclua_decode_uri( lua_State *L )
{
int i_top = lua_gettop( L );
int i;
for( i = 1; i <= i_top; i++ )
{
const char *psz_cstring = luaL_checkstring( L, 1 );
char *psz_string = strdup( psz_cstring );
lua_remove( L, 1 ); /* remove elements to prevent being limited by
* the stack's size (this function will work with
* up to (stack size - 1) arguments */
decode_URI( psz_string );
lua_pushstring( L, psz_string );
free( psz_string );
}
return i_top;
}
static int vlclua_resolve_xml_special_chars( lua_State *L )
{
int i_top = lua_gettop( L );
int i;
for( i = 1; i <= i_top; i++ )
{
const char *psz_cstring = luaL_checkstring( L, 1 );
char *psz_string = strdup( psz_cstring );
lua_remove( L, 1 ); /* remove elements to prevent being limited by
* the stack's size (this function will work with
* up to (stack size - 1) arguments */
resolve_xml_special_chars( psz_string );
lua_pushstring( L, psz_string );
free( psz_string );
}
return i_top;
}
static int vlclua_convert_xml_special_chars( lua_State *L )
{
int i_top = lua_gettop( L );
int i;
for( i = 1; i <= i_top; i++ )
{
char *psz_string = convert_xml_special_chars( luaL_checkstring(L,1) );
lua_remove( L, 1 );
lua_pushstring( L, psz_string );
free( psz_string );
}
return i_top;
}
/*****************************************************************************
*
*****************************************************************************/
static const luaL_Reg vlclua_strings_reg[] = {
{ "decode_uri", vlclua_decode_uri },
{ "resolve_xml_special_chars", vlclua_resolve_xml_special_chars },
{ "convert_xml_special_chars", vlclua_convert_xml_special_chars },
{ NULL, NULL }
};
void luaopen_strings( lua_State *L )
{
lua_newtable( L );
luaL_register( L, NULL, vlclua_strings_reg );
lua_setfield( L, -2, "strings" );
}
/*****************************************************************************
* variables.h: Generic lua<->vlc variables interface
*****************************************************************************
* Copyright (C) 2007-2008 the VideoLAN team
* $Id$
*
* Authors: Antoine Cellerier <dionoea at videolan tod org>
* Pierre d'Herbemont <pdherbemont # videolan.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.
*****************************************************************************/
#ifndef VLC_LUA_VARIABLES_H
#define VLC_LUA_VARIABLES_H
int vlclua_pushvalue( lua_State *L, int i_type, vlc_value_t val ); /* internal use only */
#define vlclua_var_toggle_or_set(a,b,c) \
__vlclua_var_toggle_or_set(a,VLC_OBJECT(b),c)
int __vlclua_var_toggle_or_set( lua_State *, vlc_object_t *, const char * );
#endif
/*****************************************************************************
* intf.c: Generic lua interface functions
*****************************************************************************
* 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_vout.h>
#include <lua.h> /* Low level lua C API */
#include <lauxlib.h> /* Higher level C API */
#include "../vlc.h"
#include "../libs.h"
#include "input.h"
#include "variables.h"
/*****************************************************************************
* Vout control
*****************************************************************************/
static int vlclua_fullscreen( lua_State *L )
{
vout_thread_t *p_vout;
int i_ret;
input_thread_t * p_input = vlclua_get_input_internal( L );
if( !p_input ) return vlclua_error( L );
p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
if( !p_vout ) return vlclua_error( L );
i_ret = vlclua_var_toggle_or_set( L, p_vout, "fullscreen" );
vlc_object_release( p_vout );
vlc_object_release( p_input );
return i_ret;
}
/*****************************************************************************
*
*****************************************************************************/
static const luaL_Reg vlclua_video_reg[] = {
{ "fullscreen", vlclua_fullscreen },
{ NULL, NULL }
};
void luaopen_video( lua_State *L )
{
lua_newtable( L );
luaL_register( L, NULL, vlclua_video_reg );
lua_setfield( L, -2, "video" );
}
/***************************************************************************** /*****************************************************************************
* objects.c: Generic lua VLM wrapper * vlm.c: Generic lua VLM wrapper
***************************************************************************** *****************************************************************************
* Copyright (C) 2007 the VideoLAN team * Copyright (C) 2007-2008 the VideoLAN team
* $Id$ * $Id$
* *
* Authors: Antoine Cellerier <dionoea at videolan tod org> * Authors: Antoine Cellerier <dionoea at videolan tod org>
...@@ -37,37 +37,52 @@ ...@@ -37,37 +37,52 @@
#include <lua.h> /* Low level lua C API */ #include <lua.h> /* Low level lua C API */
#include <lauxlib.h> /* Higher level C API */ #include <lauxlib.h> /* Higher level C API */
#include <lualib.h> /* Lua libs */
#include "vlc.h" #include "../vlc.h"
#include "../libs.h"
/***************************************************************************** /*****************************************************************************
* *
*****************************************************************************/ *****************************************************************************/
int vlclua_vlm_new( lua_State *L )
{
#ifdef ENABLE_VLM #ifdef ENABLE_VLM
static int vlclua_vlm_delete( lua_State * );
static int vlclua_vlm_execute_command( lua_State * );
static const luaL_Reg vlclua_vlm_reg[] = {
{ "execute_command", vlclua_vlm_execute_command },
{ NULL, NULL }
};
static int vlclua_vlm_new( lua_State *L )
{
vlc_object_t *p_this = vlclua_get_this( L ); vlc_object_t *p_this = vlclua_get_this( L );
vlm_t *p_vlm = vlm_New( p_this ); vlm_t *p_vlm = vlm_New( p_this );
if( !p_vlm ) if( !p_vlm )
goto err; return luaL_error( L, "Cannot start VLM." );
__vlclua_push_vlc_object( L, (vlc_object_t*)p_vlm, NULL );
vlm_t **pp_vlm = lua_newuserdata( L, sizeof( vlm_t * ) );
*pp_vlm = p_vlm;
if( luaL_newmetatable( L, "vlm" ) )
{
lua_newtable( L );
luaL_register( L, NULL, vlclua_vlm_reg );
lua_setfield( L, -2, "__index" );
lua_pushcfunction( L, vlclua_vlm_delete );
lua_setfield( L, -2, "__gc" );
}
lua_setmetatable( L, -2 );
return 1; return 1;
err:
#endif
return luaL_error( L, "Cannot start VLM." );
} }
int vlclua_vlm_delete( lua_State *L ) static int vlclua_vlm_delete( lua_State *L )
{ {
#ifdef ENABLE_VLM vlm_t **pp_vlm = (vlm_t**)luaL_checkudata( L, 1, "vlm" );
vlm_t *p_vlm = (vlm_t*)vlclua_checkobject( L, 1, VLC_OBJECT_GENERIC ); vlm_Delete( *pp_vlm );
vlm_Delete( p_vlm );
#endif
return 0; return 0;
} }
#ifdef ENABLE_VLM
static void push_message( lua_State *L, vlm_message_t *message ) static void push_message( lua_State *L, vlm_message_t *message )
{ {
lua_createtable( L, 0, 2 ); lua_createtable( L, 0, 2 );
...@@ -92,21 +107,31 @@ static void push_message( lua_State *L, vlm_message_t *message ) ...@@ -92,21 +107,31 @@ static void push_message( lua_State *L, vlm_message_t *message )
} }
} }
int vlclua_vlm_execute_command( lua_State *L ) static int vlclua_vlm_execute_command( lua_State *L )
{ {
vlm_t *p_vlm = (vlm_t*)vlclua_checkobject( L, 1, VLC_OBJECT_GENERIC ); vlm_t **pp_vlm = (vlm_t**)luaL_checkudata( L, 1, "vlm" );
const char *psz_command = luaL_checkstring( L, 2 ); const char *psz_command = luaL_checkstring( L, 2 );
vlm_message_t *message; vlm_message_t *message;
int i_ret; int i_ret;
i_ret = vlm_ExecuteCommand( p_vlm, psz_command, &message ); i_ret = vlm_ExecuteCommand( *pp_vlm, psz_command, &message );
lua_settop( L, 0 ); lua_settop( L, 0 );
push_message( L, message ); push_message( L, message );
vlm_MessageDelete( message ); vlm_MessageDelete( message );
return 1 + vlclua_push_ret( L, i_ret ); return 1 + vlclua_push_ret( L, i_ret );
} }
#else #else
int vlclua_vlm_execute_command( lua_State *L ) static int vlclua_vlm_new( lua_State *L )
{ {
return 1 + vlclua_push_ret( L, VLC_EGENERIC ); return luaL_error( L, "Cannot start VLM because it was disabled when compiling VLC." );
} }
#endif #endif
/*****************************************************************************
*
*****************************************************************************/
void luaopen_vlm( lua_State *L )
{
lua_pushcfunction( L, vlclua_vlm_new );
lua_setfield( L, -2, "vlm" );
}
/*****************************************************************************
* volume.c
*****************************************************************************
* Copyright (C) 2007-2008 the VideoLAN team
* $Id$
*
* Authors: Antoine Cellerier <dionoea at videolan tod org>
* Pierre d'Herbemont <pdherbemont # videolan.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_plugin.h>
#include <vlc_meta.h>
#include <vlc_charset.h>
#include <vlc_aout.h>
#include <lua.h> /* Low level lua C API */
#include <lauxlib.h> /* Higher level C API */
#include <lualib.h> /* Lua libs */
#include "../vlc.h"
#include "../libs.h"
/*****************************************************************************
* Volume related
*****************************************************************************/
static int vlclua_volume_set( lua_State *L )
{
vlc_object_t *p_this = vlclua_get_this( L );
int i_volume = luaL_checkint( L, 1 );
/* Do we need to check that i_volume is in the AOUT_VOLUME_MIN->MAX range?*/
return vlclua_push_ret( L, aout_VolumeSet( p_this, i_volume ) );
}
static int vlclua_volume_get( lua_State *L )
{
vlc_object_t *p_this = vlclua_get_this( L );
audio_volume_t i_volume;
if( aout_VolumeGet( p_this, &i_volume ) == VLC_SUCCESS )
lua_pushnumber( L, i_volume );
else
lua_pushnil( L );
return 1;
}
static int vlclua_volume_up( lua_State *L )
{
audio_volume_t i_volume;
aout_VolumeUp( vlclua_get_this( L ),
luaL_optint( L, 1, 1 ),
&i_volume );
lua_pushnumber( L, i_volume );
return 1;
}
static int vlclua_volume_down( lua_State *L )
{
audio_volume_t i_volume;
aout_VolumeDown( vlclua_get_this( L ),
luaL_optint( L, 1, 1 ),
&i_volume );
lua_pushnumber( L, i_volume );
return 1;
}
/*****************************************************************************
*
*****************************************************************************/
static const luaL_Reg vlclua_volume_reg[] = {
{ "get", vlclua_volume_get },
{ "set", vlclua_volume_set },
{ "up", vlclua_volume_up },
{ "down", vlclua_volume_down },
{ NULL, NULL }
};
void luaopen_volume( lua_State *L )
{
lua_newtable( L );
luaL_register( L, NULL, vlclua_volume_reg );
lua_setfield( L, -2, "volume" );
}
/***************************************************************************** /*****************************************************************************
* meta.c: Get meta/artwork using lua scripts * meta.c: Get meta/artwork using lua scripts
***************************************************************************** *****************************************************************************
* Copyright (C) 2007 the VideoLAN team * Copyright (C) 2007-2008 the VideoLAN team
* $Id$ * $Id$
* *
* Authors: Antoine Cellerier <dionoea at videolan tod org> * Authors: Antoine Cellerier <dionoea at videolan tod org>
...@@ -43,52 +43,18 @@ ...@@ -43,52 +43,18 @@
#include <vlc_charset.h> #include <vlc_charset.h>
#include "vlc.h" #include "vlc.h"
#include "libs.h"
/***************************************************************************** /*****************************************************************************
* Local prototypes * Local prototypes
*****************************************************************************/ *****************************************************************************/
static int fetch_meta( vlc_object_t *p_this, const char * psz_filename,
lua_State * L, void * user_data );
static int fetch_art( vlc_object_t *p_this, const char * psz_filename, static int fetch_art( vlc_object_t *p_this, const char * psz_filename,
lua_State * L, void * user_data ); lua_State * L, void * user_data );
static lua_State *vlclua_meta_init( vlc_object_t *p_this, static lua_State *vlclua_meta_init( vlc_object_t *p_this,
input_item_t * p_item ); input_item_t * p_item );
/*****************************************************************************
* Lua function bridge
*****************************************************************************/
/* Functions to register */
static luaL_Reg p_reg[] =
{
/* TODO: make an object out of the stream stuff, so we can do something
* like:
*
* s = vlc.stream_new( "http://www.videolan.org" )
* page = s:read( 2^16 )
* s:delete()
*
* instead of (which could be problematic since we don't check if
* s is really a stream object):
*
* s = vlc.stream_new( "http://www.videolan.org" )
* page = vlc.stream_read( s, 2^16 )
* vlc.stream_delete( s )
*/
{ "stream_new", vlclua_stream_new },
{ "stream_read", vlclua_stream_read },
{ "stream_readline", vlclua_stream_readline },
{ "stream_delete", vlclua_stream_delete },
{ "decode_uri", vlclua_decode_uri },
{ "resolve_xml_special_chars", vlclua_resolve_xml_special_chars },
{ "msg_dbg", vlclua_msg_dbg },
{ "msg_warn", vlclua_msg_warn },
{ "msg_err", vlclua_msg_err },
{ "msg_info", vlclua_msg_info },
{ NULL, NULL }
};
/***************************************************************************** /*****************************************************************************
* Init lua * Init lua
*****************************************************************************/ *****************************************************************************/
...@@ -105,7 +71,11 @@ static lua_State * vlclua_meta_init( vlc_object_t *p_this, input_item_t * p_item ...@@ -105,7 +71,11 @@ static lua_State * vlclua_meta_init( vlc_object_t *p_this, input_item_t * p_item
/* Load Lua libraries */ /* Load Lua libraries */
luaL_openlibs( L ); /* XXX: Don't open all the libs? */ luaL_openlibs( L ); /* XXX: Don't open all the libs? */
luaL_register( L, "vlc", p_reg ); luaL_register( L, "vlc", NULL /* FIXME ? */ );
luaopen_msg( L );
luaopen_stream( L );
luaopen_strings( L );
lua_pushlightuserdata( L, p_this ); lua_pushlightuserdata( L, p_this );
lua_setfield( L, -2, "private" ); lua_setfield( L, -2, "private" );
...@@ -211,73 +181,6 @@ static int fetch_art( vlc_object_t *p_this, const char * psz_filename, ...@@ -211,73 +181,6 @@ static int fetch_art( vlc_object_t *p_this, const char * psz_filename,
return i_ret; return i_ret;
} }
/*****************************************************************************
* Called through lua_scripts_batch_execute to call 'fetch_meta' on the script
* pointed by psz_filename.
*****************************************************************************/
static int fetch_meta( vlc_object_t *p_this, const char * psz_filename,
lua_State * L, void * user_data )
{
input_item_t * p_input = user_data;
/* In lua, setting a variable to nil is equivalent to deleting it */
lua_pushnil( L );
lua_setglobal( L, "fetch_meta" );
/* Load and run the script(s) */
if( luaL_dofile( L, psz_filename ) )
{
msg_Warn( p_this, "Error loading script %s: %s", psz_filename,
lua_tostring( L, lua_gettop( L ) ) );
lua_pop( L, 1 );
return VLC_EGENERIC;
}
lua_getglobal( L, "fetch_meta" );
if( !lua_isfunction( L, lua_gettop( L ) ) )
{
msg_Warn( p_this, "Error while runing script %s, "
"function fetch_meta() not found", psz_filename );
lua_pop( L, 1 );
return VLC_EGENERIC;
}
if( lua_pcall( L, 0, 1, 0 ) )
{
msg_Warn( p_this, "Error while runing script %s, "
"function fetch_meta(): %s", psz_filename,
lua_tostring( L, lua_gettop( L ) ) );
lua_pop( L, 1 );
return VLC_EGENERIC;
}
if( lua_gettop( L ) )
{
if( lua_istable( L, -1 ) )
{
/* ... item */
vlclua_read_meta_data( p_this, L, p_input );
vlclua_read_custom_meta_data( p_this, L, p_input );
}
else
{
msg_Err( p_this, "Lua playlist script %s: "
"didn't return a table", psz_filename );
}
}
else
{
msg_Err( p_this, "Script went completely foobar" );
}
/* We tell the batch thing to continue, hence all script
* will get the change to add its meta. This behaviour could
* be changed. */
return VLC_EGENERIC;
}
/***************************************************************************** /*****************************************************************************
* Module entry point for art. * Module entry point for art.
*****************************************************************************/ *****************************************************************************/
......
/*****************************************************************************
* variables.c: Generic lua<->vlc variables interface
*****************************************************************************
* Copyright (C) 2007 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 <lua.h> /* Low level lua C API */
#include <lauxlib.h> /* Higher level C API */
#include <lualib.h> /* Lua libs */
#include "vlc.h"
/*****************************************************************************
* Variables handling
*****************************************************************************/
int vlclua_pushvalue( lua_State *L, int i_type, vlc_value_t val )
{
switch( i_type &= 0xf0 )
{
case VLC_VAR_VOID:
vlclua_error( L );
break;
case VLC_VAR_BOOL:
lua_pushboolean( L, val.b_bool );
break;
case VLC_VAR_INTEGER:
lua_pushinteger( L, val.i_int );
break;
case VLC_VAR_STRING:
lua_pushstring( L, val.psz_string );
break;
case VLC_VAR_FLOAT:
lua_pushnumber( L, val.f_float );
break;
case VLC_VAR_TIME:
/* FIXME? (we're losing some precision, but does it really matter?) */
lua_pushnumber( L, ((double)val.i_time)/1000000. );
break;
case VLC_VAR_ADDRESS:
vlclua_error( L );
break;
case VLC_VAR_MUTEX:
vlclua_error( L );
break;
case VLC_VAR_LIST:
{
int i_count = val.p_list->i_count;
int i;
lua_createtable( L, i_count, 0 );
for( i = 0; i < i_count; i++ )
{
lua_pushinteger( L, i+1 );
if( !vlclua_pushvalue( L, val.p_list->pi_types[i],
val.p_list->p_values[i] ) )
lua_pushnil( L );
lua_settable( L, -3 );
}
}
break;
default:
vlclua_error( L );
}
return 1;
}
static int vlclua_tovalue( lua_State *L, int i_type, vlc_value_t *val )
{
switch( i_type & 0xf0 )
{
case VLC_VAR_VOID:
break;
case VLC_VAR_BOOL:
val->b_bool = luaL_checkboolean( L, -1 );
break;
case VLC_VAR_INTEGER:
val->i_int = luaL_checkint( L, -1 );
break;
case VLC_VAR_STRING:
val->psz_string = (char*)luaL_checkstring( L, -1 ); /* XXX: Beware, this only stays valid as long as (L,-1) stays in the stack */
break;
case VLC_VAR_FLOAT:
val->f_float = luaL_checknumber( L, -1 );
break;
case VLC_VAR_TIME:
{
double f = luaL_checknumber( L, -1 );
val->i_time = (int64_t)(f*1000000.);
}
break;
case VLC_VAR_ADDRESS:
vlclua_error( L );
break;
case VLC_VAR_MUTEX:
vlclua_error( L );
break;
case VLC_VAR_LIST:
vlclua_error( L );
break;
default:
vlclua_error( L );
}
return 1;
}
int vlclua_var_get( lua_State *L )
{
int i_type;
vlc_value_t val;
vlc_object_t *p_obj = vlclua_checkobject( L, 1, 0 );
const char *psz_var = luaL_checkstring( L, 2 );
i_type = var_Type( p_obj, psz_var );
var_Get( p_obj, psz_var, &val );
lua_pop( L, 2 );
return vlclua_pushvalue( L, i_type, val );
}
int vlclua_var_set( lua_State *L )
{
int i_type;
vlc_value_t val;
vlc_object_t *p_obj = vlclua_checkobject( L, 1, 0 );
const char *psz_var = luaL_checkstring( L, 2 );
int i_ret;
i_type = var_Type( p_obj, psz_var );
vlclua_tovalue( L, i_type, &val );
i_ret = var_Set( p_obj, psz_var, val );
lua_pop( L, 3 );
return vlclua_push_ret( L, i_ret );
}
int vlclua_var_get_list( lua_State *L )
{
vlc_value_t val;
vlc_value_t text;
vlc_object_t *p_obj = vlclua_checkobject( L, 1, 0 );
const char *psz_var = luaL_checkstring( L, 2 );
int i_ret = var_Change( p_obj, psz_var, VLC_VAR_GETLIST, &val, &text );
if( i_ret < 0 ) return vlclua_push_ret( L, i_ret );
vlclua_pushvalue( L, VLC_VAR_LIST, val );
vlclua_pushvalue( L, VLC_VAR_LIST, text );
var_Change( p_obj, psz_var, VLC_VAR_FREELIST, &val, &text );
return 2;
}
int vlclua_module_command( lua_State *L )
{
vlc_object_t * p_this = vlclua_get_this( L );
const char *psz_name;
const char *psz_cmd;
const char *psz_arg;
char *psz_msg;
psz_name = luaL_checkstring( L, 1 );
psz_cmd = luaL_checkstring( L, 2 );
psz_arg = luaL_checkstring( L, 3 );
lua_pop( L, 3 );
var_Command( p_this, psz_name, psz_cmd, psz_arg, &psz_msg );
if( psz_msg )
{
lua_pushstring( L, psz_msg );
free( psz_msg );
}
else
{
lua_pushstring( L, "" );
}
return 1;
}
int vlclua_libvlc_command( lua_State *L )
{
vlc_object_t * p_this = vlclua_get_this( L );
const char *psz_cmd;
vlc_value_t val_arg;
psz_cmd = luaL_checkstring( L, 1 );
val_arg.psz_string = strdup( luaL_optstring( L, 2, "" ) );
lua_pop( L, 2 );
if( !var_Type( p_this->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
{
free( val_arg.psz_string );
return luaL_error( L, "libvlc's \"%s\" is not a command",
psz_cmd );
}
return vlclua_push_ret( L,
var_Set( p_this->p_libvlc, psz_cmd, val_arg ) );
}
This diff is collapsed.
This diff is collapsed.
...@@ -295,8 +295,6 @@ DIST_lua= \ ...@@ -295,8 +295,6 @@ DIST_lua= \
lua/intf/hotkeys.lua \ lua/intf/hotkeys.lua \
lua/intf/modules/common.lua \ lua/intf/modules/common.lua \
lua/intf/modules/host.lua \ lua/intf/modules/host.lua \
lua/intf/modules/httpd.lua \
lua/intf/modules/acl.lua \
lua/intf/modules/sandbox.lua \ lua/intf/modules/sandbox.lua \
lua/intf/telnet.lua \ lua/intf/telnet.lua \
lua/intf/dummy.lua lua/intf/dummy.lua
......
--[==========================================================================[
acl.lua: VLC Lua interface ACL object
--[==========================================================================[
Copyright (C) 2007 the VideoLAN team
$Id$
Authors: Antoine Cellerier <dionoea at videolan dot 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.
--]==========================================================================]
--[==========================================================================[
require "acl"
local a = acl.new(true) -> new ACL with default set to allow
a:check("10.0.0.1") -> 0 == allow, 1 == deny, -1 == error
a("10.0.0.1") -> same as a:check("10.0.0.1")
a:duplicate() -> duplicate ACL object
a:add_host("10.0.0.1",true) -> allow 10.0.0.1
a:add_net("10.0.0.0",24,true) -> allow 10.0.0.0/24 (not sure)
a:load_file("/path/to/acl") -> load ACL from file
--]==========================================================================]
module("acl",package.seeall)
methods = {
check = function(this,ip)
return vlc.acl.check(this.private,ip)
end,
duplicate = function(this)
return setmetatable({ private = vlc.acl.duplicate( rawget(this,"private") ) },metatable)
end,
add_host = function(this,ip,allow)
return vlc.acl.add_host(this.private,ip,allow)
end,
add_net = function(this,ip,len,allow)
return vlc.acl.add_net(this.private,ip,len,allow)
end,
load_file = function(this,path)
return vlc.acl.load_file(this.private,path)
end,
}
metatable = {
__index = function(this,key)
if methods[key] then
return methods[key]
elseif key == "private" then
error("Forbidden")
else
return rawget(this,key)
end
end,
__newindex = function(this,key,value)
if key == "private" or methods[key] then
error("Forbidden")
else
rawset(this,key,value)
end
end,
__call = methods.check,
__gc = function(this)
vlc.acl.delete(this.private)
end,
__metatable = "None of your business.",
}
function new( allow )
return setmetatable({ private = vlc.acl.create( allow ) },metatable)
end
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment