summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--stream.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/stream.c b/stream.c
index a7219ac..781c821 100644
--- a/stream.c
+++ b/stream.c
@@ -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;
}