From 1aceae67491cd871c1be063ba7f02bf6db85a1fa Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Feb 2021 22:38:08 +0100 Subject: Added arguments to stream's read --- stream.c | 15 +++++++++++++-- 1 file 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; } -- cgit v1.1