| 389 | |
| 390 | |
| 391 | static int io_readline (lua_State *L) { |
| 392 | FILE *f = *(FILE **)lua_touserdata(L, lua_upvalueindex(1)); |
| 393 | int sucess; |
| 394 | if (f == NULL) /* file is already closed? */ |
| 395 | luaL_error(L, "file is already closed"); |
| 396 | sucess = read_line(L, f); |
| 397 | if (ferror(f)) |
| 398 | return luaL_error(L, "%s", strerror(errno)); |
| 399 | if (sucess) return 1; |
| 400 | else { /* EOF */ |
| 401 | if (lua_toboolean(L, lua_upvalueindex(2))) { /* generator created file? */ |
| 402 | lua_settop(L, 0); |
| 403 | lua_pushvalue(L, lua_upvalueindex(1)); |
| 404 | aux_close(L); /* close it */ |
| 405 | } |
| 406 | return 0; |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | /* }====================================================== */ |
| 411 |
nothing calls this directly
no test coverage detected