[vlc-devel] commit: Add lua wrapper for memory stream constructor. (Antoine Cellerier )

git version control git at videolan.org
Sat Feb 13 16:39:05 CET 2010


vlc | branch: master | Antoine Cellerier <dionoea at videolan.org> | Sat Feb 13 15:31:39 2010 +0100| [9794aa0652e2e3f53fd7208c9819cc7983d69172] | committer: Antoine Cellerier 

Add lua wrapper for memory stream constructor.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9794aa0652e2e3f53fd7208c9819cc7983d69172
---

 modules/misc/lua/libs/stream.c |   28 +++++++++++++++++++++-------
 1 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/modules/misc/lua/libs/stream.c b/modules/misc/lua/libs/stream.c
index b44507f..7af8444 100644
--- a/modules/misc/lua/libs/stream.c
+++ b/modules/misc/lua/libs/stream.c
@@ -59,15 +59,10 @@ static const luaL_Reg vlclua_stream_reg[] = {
     { NULL, NULL }
 };
 
-static int vlclua_stream_new( lua_State *L )
+static int vlclua_stream_new_inner( lua_State *L, stream_t *p_stream )
 {
-    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 );
+        return luaL_error( L, "Error when opening stream" );
 
     stream_t **pp_stream = lua_newuserdata( L, sizeof( stream_t * ) );
     *pp_stream = p_stream;
@@ -85,6 +80,23 @@ static int vlclua_stream_new( lua_State *L )
     return 1;
 }
 
+static int vlclua_stream_new( lua_State *L )
+{
+    vlc_object_t * p_this = vlclua_get_this( L );
+    const char * psz_url = luaL_checkstring( L, 1 );
+    stream_t *p_stream = stream_UrlNew( p_this, psz_url );
+    return vlclua_stream_new_inner( L, p_stream );
+}
+
+static int vlclua_memory_stream_new( lua_State *L )
+{
+    vlc_object_t * p_this = vlclua_get_this( L );
+    /* FIXME: duplicating the whole buffer is suboptimal. Keeping a reference to the string so that it doesn't get garbage collected would be better */
+    const char * psz_content = strdup( luaL_checkstring( L, 1 ) );
+    stream_t *p_stream = stream_MemoryNew( p_this, psz_content, strlen( psz_content ), false );
+    return vlclua_stream_new_inner( L, p_stream );
+}
+
 static int vlclua_stream_read( lua_State *L )
 {
     int i_read;
@@ -176,4 +188,6 @@ void luaopen_stream( lua_State *L )
 {
     lua_pushcfunction( L, vlclua_stream_new );
     lua_setfield( L, -2, "stream" );
+    lua_pushcfunction( L, vlclua_memory_stream_new );
+    lua_setfield( L, -2, "memory_stream" );
 }




More information about the vlc-devel mailing list