diff options
-rw-r--r-- | stream.c | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -74,7 +74,14 @@ int stream_gc(lua_State * L) /// \return Number of the results pushed to the stack int stream_read(lua_State * L) { - struct stream * s = lua_touserdata(L, -1); + int n = lua_gettop(L); + if (2 > n) + { + lua_pushliteral(L, "At least two arguments expected"); + return lua_error(L); + } + + struct stream * s = lua_touserdata(L, 1); if (NULL == s) { @@ -129,7 +136,11 @@ int stream_readk(lua_State * L, int status, lua_KContext ctx) s->in.offset = 0; lua_pushstring(L, s->in.data); - lua_remove(L, -2); + + for (int n = -lua_gettop(L); n < -1; ++n) + { + lua_remove(L, n); + } return 1; } |