Commit 1202f7e6 authored by Rémi Duraffort's avatar Rémi Duraffort

lua_demux: return nil when read/peek fails.

parent 6e5543ce
...@@ -60,8 +60,12 @@ static int vlclua_demux_peek( lua_State *L ) ...@@ -60,8 +60,12 @@ static int vlclua_demux_peek( lua_State *L )
demux_t *p_demux = (demux_t *)vlclua_get_this( L ); demux_t *p_demux = (demux_t *)vlclua_get_this( L );
int n = luaL_checkint( L, 1 ); int n = luaL_checkint( L, 1 );
const uint8_t *p_peek; const uint8_t *p_peek;
int i_peek = stream_Peek( p_demux->s, &p_peek, n ); int i_peek = stream_Peek( p_demux->s, &p_peek, n );
if( i_peek > 0 )
lua_pushlstring( L, (const char *)p_peek, i_peek ); lua_pushlstring( L, (const char *)p_peek, i_peek );
else
lua_pushnil( L );
return 1; return 1;
} }
...@@ -71,9 +75,16 @@ static int vlclua_demux_read( lua_State *L ) ...@@ -71,9 +75,16 @@ static int vlclua_demux_read( lua_State *L )
const uint8_t *p_read; const uint8_t *p_read;
int n = luaL_checkint( L, 1 ); int n = luaL_checkint( L, 1 );
int i_read = stream_Peek( p_demux->s, &p_read, n ); int i_read = stream_Peek( p_demux->s, &p_read, n );
if( i_read > 0 )
{
lua_pushlstring( L, (const char *)p_read, i_read ); lua_pushlstring( L, (const char *)p_read, i_read );
int i_seek = stream_Read( p_demux->s, NULL, i_read ); int i_seek = stream_Read( p_demux->s, NULL, i_read );
assert(i_read==i_seek); assert( i_read == i_seek );
}
else
lua_pushnil( L );
return 1; 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