[vlc-devel] [PATCH 10/10] Lua: allow scripts to add stream filters
Jean-Philippe André
jpeg at videolan.org
Thu Nov 12 00:08:10 CET 2009
---
modules/misc/lua/libs/stream.c | 40 +++++++++++++++++++++++++++++++++++++++-
1 files changed, 39 insertions(+), 1 deletions(-)
diff --git a/modules/misc/lua/libs/stream.c b/modules/misc/lua/libs/stream.c
index 49e48b3..6a08335 100644
--- a/modules/misc/lua/libs/stream.c
+++ b/modules/misc/lua/libs/stream.c
@@ -51,10 +51,12 @@
static int vlclua_stream_read( lua_State * );
static int vlclua_stream_readline( lua_State * );
static int vlclua_stream_delete( lua_State * );
+static int vlclua_stream_add_filter( lua_State *L );
static const luaL_Reg vlclua_stream_reg[] = {
{ "read", vlclua_stream_read },
{ "readline", vlclua_stream_readline },
+ { "addfilter", vlclua_stream_add_filter },
{ NULL, NULL }
};
@@ -88,6 +90,7 @@ static int vlclua_stream_read( lua_State *L )
{
int i_read;
stream_t **pp_stream = (stream_t **)luaL_checkudata( L, 1, "stream" );
+ if( !*pp_stream ) return vlclua_error( L );
int n = luaL_checkint( L, 2 );
uint8_t *p_read = malloc( n );
if( !p_read ) return vlclua_error( L );
@@ -100,6 +103,7 @@ static int vlclua_stream_read( lua_State *L )
static int vlclua_stream_readline( lua_State *L )
{
stream_t **pp_stream = (stream_t **)luaL_checkudata( L, 1, "stream" );
+ if( !*pp_stream ) return vlclua_error( L );
char *psz_line = stream_ReadLine( *pp_stream );
if( psz_line )
{
@@ -114,10 +118,44 @@ static int vlclua_stream_readline( lua_State *L )
static int vlclua_stream_delete( lua_State *L )
{
stream_t **pp_stream = (stream_t **)luaL_checkudata( L, 1, "stream" );
- stream_Delete( *pp_stream );
+ if( *pp_stream )
+ {
+ stream_Delete( *pp_stream );
+ *pp_stream = NULL;
+ }
+ else
+ return vlclua_error( L );
return 0;
}
+static int vlclua_stream_add_filter( lua_State *L )
+{
+ vlc_object_t *p_this = vlclua_get_this( L );
+ stream_t **pp_stream = (stream_t **)luaL_checkudata( L, 1, "stream" );
+ if( !*pp_stream ) return vlclua_error( L );
+ const char *psz_filter = luaL_checkstring( L, 2 );
+
+ stream_t *p_filter = stream_FilterNew( *pp_stream, psz_filter );
+ if( !p_filter )
+ {
+ msg_Dbg( p_this, "Unable to open requested stream filter '%s'",
+ psz_filter );
+ lua_pushinteger( L, 0 );
+ }
+ else
+ {
+ msg_Dbg( p_this, "Successfully opened stream filter '%s'",
+ psz_filter );
+ *pp_stream = p_filter;
+
+ luaL_getmetatable( L, "stream" );
+ lua_setmetatable( L, 1 );
+
+ lua_pushinteger( L, 1 );
+ }
+ return 1;
+}
+
/*****************************************************************************
*
*****************************************************************************/
--
1.6.5.2
More information about the vlc-devel
mailing list