summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/plugins/lua/liolib.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/apps/plugins/lua/liolib.c b/apps/plugins/lua/liolib.c
index 6744efedd5..fb6765492b 100644
--- a/apps/plugins/lua/liolib.c
+++ b/apps/plugins/lua/liolib.c
@@ -269,22 +269,19 @@ static int _read_line (lua_State *L, int *f) {
269 luaL_buffinit(L, &b); 269 luaL_buffinit(L, &b);
270 for (;;) { 270 for (;;) {
271 size_t l; 271 size_t l;
272 off_t r;
273 char *p = luaL_prepbuffer(&b); 272 char *p = luaL_prepbuffer(&b);
274 r = rb->read_line(*f, p, LUAL_BUFFERSIZE); 273 off_t r = rb->read_line(*f, p, LUAL_BUFFERSIZE); /* does not include `eol' */
275 l = strlen(p); 274 if (r <= 0) { /* eof? */
276
277 if (l == 0 || p[l-1] != '\n')
278 luaL_addsize(&b, l);
279 else {
280 luaL_addsize(&b, l - 1); /* do not include `eol' */
281 luaL_pushresult(&b); /* close buffer */ 275 luaL_pushresult(&b); /* close buffer */
282 return 1; /* read at least an `eol' */ 276 return (lua_objlen(L, -1) > 0); /* check whether read something */
283 }
284 if (r < LUAL_BUFFERSIZE) { /* eof? */
285 luaL_pushresult(&b); /* close buffer */
286 return (r > 0); /* check whether read something */
287 } 277 }
278 l = strlen(p);
279 luaL_addsize(&b, l);
280 if(r >= LUAL_BUFFERSIZE - 1)
281 continue; /* more to read */
282
283 luaL_pushresult(&b); /* close buffer */
284 return 1; /* we read at least 1 character */
288 } 285 }
289} 286}
290 287