]> git.sesse.net Git - vlc/commitdiff
lua: return nil when the stream or file ends (fix #4876)
authorRémi Duraffort <ivoire@videolan.org>
Wed, 8 Jun 2011 18:24:26 +0000 (20:24 +0200)
committerRémi Duraffort <ivoire@videolan.org>
Wed, 8 Jun 2011 18:25:18 +0000 (20:25 +0200)
modules/lua/libs/net.c
modules/lua/libs/stream.c

index c4696b318d26ebd30ad1fd3e29cb48eb37bc056d..e2b3c45577cc65ed37261cf6a2aaddd64eef83ed 100644 (file)
@@ -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;
 }
 
index 4dcae620646de25394b1cc71ab42fcdbef2c194a..ef7187cac94ab8d94eaa2687336a0ae53848c931 100644 (file)
@@ -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;
 }