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