[vlc-commits] lua: return nil when the stream or file ends (fix #4876)
Rémi Duraffort
git at videolan.org
Wed Jun 8 20:31:18 CEST 2011
vlc | branch: master | Rémi Duraffort <ivoire at videolan.org> | Wed Jun 8 20:24:26 2011 +0200| [b0d7c77b11a477cb2d2d7bf86e8c4b9f2c4bbeb1] | committer: Rémi Duraffort
lua: return nil when the stream or file ends (fix #4876)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b0d7c77b11a477cb2d2d7bf86e8c4b9f2c4bbeb1
---
modules/lua/libs/net.c | 5 ++++-
modules/lua/libs/stream.c | 6 +++++-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/modules/lua/libs/net.c b/modules/lua/libs/net.c
index c4696b3..e2b3c45 100644
--- a/modules/lua/libs/net.c
+++ b/modules/lua/libs/net.c
@@ -265,7 +265,10 @@ static int vlclua_fd_read( lua_State *L )
size_t i_len = luaL_optint( L, 2, 1 );
char psz_buffer[i_len];
ssize_t i_ret = read( i_fd, psz_buffer, i_len );
- lua_pushlstring( L, psz_buffer, (i_ret >= 0) ? i_ret : 0 );
+ if( i_ret > 0 )
+ lua_pushlstring( L, psz_buffer, i_ret );
+ else
+ lua_pushnil( L );
return 1;
}
diff --git a/modules/lua/libs/stream.c b/modules/lua/libs/stream.c
index 4dcae62..ef7187c 100644
--- a/modules/lua/libs/stream.c
+++ b/modules/lua/libs/stream.c
@@ -108,8 +108,12 @@ static int vlclua_stream_read( lua_State *L )
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 );
+ if( i_read > 0 )
+ lua_pushlstring( L, (const char *)p_read, i_read );
+ else
+ lua_pushnil( L );
free( p_read );
return 1;
}
More information about the vlc-commits
mailing list