| 292 | |
| 293 | |
| 294 | static int read_line (lua_State *L, FILE *f) { |
| 295 | luaL_Buffer b; |
| 296 | luaL_buffinit(L, &b); |
| 297 | for (;;) { |
| 298 | size_t l; |
| 299 | char *p = luaL_prepbuffer(&b); |
| 300 | if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */ |
| 301 | luaL_pushresult(&b); /* close buffer */ |
| 302 | return (lua_objlen(L, -1) > 0); /* check whether read something */ |
| 303 | } |
| 304 | l = strlen(p); |
| 305 | if (l == 0 || p[l-1] != '\n') |
| 306 | luaL_addsize(&b, l); |
| 307 | else { |
| 308 | luaL_addsize(&b, l - 1); /* do not include `eol' */ |
| 309 | luaL_pushresult(&b); /* close buffer */ |
| 310 | return 1; /* read at least an `eol' */ |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | |
| 316 | static int read_chars (lua_State *L, FILE *f, size_t n) { |
no test coverage detected