[vlc-commits] lua: streams: Expose seek & getsize member functions

Hugo Beauzée-Luyssen git at videolan.org
Mon Apr 16 18:57:10 CEST 2018


vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Mon Apr 16 17:15:14 2018 +0200| [502f5c066005576aa5143ffbb8d95e0ab38deeed] | committer: Hugo Beauzée-Luyssen

lua: streams: Expose seek & getsize member functions

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

 modules/lua/libs/stream.c | 26 ++++++++++++++++++++++++++
 share/lua/README.txt      |  2 ++
 2 files changed, 28 insertions(+)

diff --git a/modules/lua/libs/stream.c b/modules/lua/libs/stream.c
index ddb3f4b31c..7f3f3e12b6 100644
--- a/modules/lua/libs/stream.c
+++ b/modules/lua/libs/stream.c
@@ -49,12 +49,16 @@ static int vlclua_stream_readline( lua_State * );
 static int vlclua_stream_delete( lua_State * );
 static int vlclua_stream_add_filter( lua_State *L );
 static int vlclua_stream_readdir( lua_State *L );
+static int vlclua_stream_getsize( lua_State *L );
+static int vlclua_stream_seek( lua_State *L );
 
 static const luaL_Reg vlclua_stream_reg[] = {
     { "read", vlclua_stream_read },
     { "readline", vlclua_stream_readline },
     { "addfilter", vlclua_stream_add_filter },
     { "readdir", vlclua_stream_readdir },
+    { "getsize", vlclua_stream_getsize },
+    { "seek", vlclua_stream_seek },
     { NULL, NULL }
 };
 
@@ -251,6 +255,28 @@ static int vlclua_stream_readdir( lua_State *L )
     return 1;
 }
 
+static int vlclua_stream_getsize( lua_State *L )
+{
+    stream_t **pp_stream = (stream_t **)luaL_checkudata( L, 1, "stream" );
+    uint64_t i_size;
+    int i_res = vlc_stream_GetSize( *pp_stream, &i_size );
+    if ( i_res != 0 )
+        return luaL_error( L, "Failed to get stream size" );
+    lua_pushnumber( L, i_size );
+    return 1;
+}
+
+static int vlclua_stream_seek( lua_State *L )
+{
+    stream_t **pp_stream = (stream_t **)luaL_checkudata( L, 1, "stream" );
+    lua_Integer i_offset = luaL_checkinteger( L, 2 );
+    if ( i_offset < 0 )
+        return luaL_error( L, "Invalid negative seek offset" );
+    int i_res = vlc_stream_Seek( *pp_stream, (uint64_t)i_offset );
+    lua_pushboolean( L, i_res == 0 );
+    return 1;
+}
+
 static int vlclua_stream_delete( lua_State *L )
 {
     stream_t **pp_stream = (stream_t **)luaL_checkudata( L, 1, "stream" );
diff --git a/share/lua/README.txt b/share/lua/README.txt
index b2e681cba6..c5a7d68642 100644
--- a/share/lua/README.txt
+++ b/share/lua/README.txt
@@ -390,6 +390,8 @@ s = vlc.stream( "http://www.videolan.org/" )
 s:read( 128 ) -- read up to 128 characters. Return 0 if no more data is available (FIXME?).
 s:readline() -- read a line. Return nil if EOF was reached.
 s:addfilter() -- add a stream filter. If no argument was specified, try to add all automatic stream filters.
+s:getsize() -- returns the size of the stream, or nil if unknown
+s:seek(offset) -- seeks from offset bytes (from the begining of the stream). Returns nil in case of error
 
 Strings
 -------



More information about the vlc-commits mailing list