Commit b0d7c77b authored by Rémi Duraffort's avatar Rémi Duraffort

lua: return nil when the stream or file ends (fix #4876)

parent 31532669
......@@ -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;
}
......
......@@ -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;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment