summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2021-02-24 22:38:08 +0100
committerAki <please@ignore.pl>2021-02-24 22:45:04 +0100
commit1aceae67491cd871c1be063ba7f02bf6db85a1fa (patch)
treeda34fd8f841cfe1be86e5f5dc9bf239630ae614d
parent140c90ec899298821c35665abc1073fa9d9446d7 (diff)
downloadplop-1aceae67491cd871c1be063ba7f02bf6db85a1fa.zip
plop-1aceae67491cd871c1be063ba7f02bf6db85a1fa.tar.gz
plop-1aceae67491cd871c1be063ba7f02bf6db85a1fa.tar.bz2
Added arguments to stream's read
-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;
}