| 589 | |
| 590 | |
| 591 | static int io_readline (lua_State *L) { |
| 592 | LStream *p = (LStream *)lua_touserdata(L, lua_upvalueindex(1)); |
| 593 | int i; |
| 594 | int n = (int)lua_tointeger(L, lua_upvalueindex(2)); |
| 595 | if (isclosed(p)) /* file is already closed? */ |
| 596 | return luaL_error(L, "file is already closed"); |
| 597 | lua_settop(L , 1); |
| 598 | luaL_checkstack(L, n, "too many arguments"); |
| 599 | for (i = 1; i <= n; i++) /* push arguments to 'g_read' */ |
| 600 | lua_pushvalue(L, lua_upvalueindex(3 + i)); |
| 601 | n = g_read(L, p->f, 2); /* 'n' is number of results */ |
| 602 | lua_assert(n > 0); /* should return at least a nil */ |
| 603 | if (lua_toboolean(L, -n)) /* read at least one value? */ |
| 604 | return n; /* return them */ |
| 605 | else { /* first result is nil: EOF or error */ |
| 606 | if (n > 1) { /* is there error information? */ |
| 607 | /* 2nd result is error message */ |
| 608 | return luaL_error(L, "%s", lua_tostring(L, -n + 1)); |
| 609 | } |
| 610 | if (lua_toboolean(L, lua_upvalueindex(3))) { /* generator created file? */ |
| 611 | lua_settop(L, 0); |
| 612 | lua_pushvalue(L, lua_upvalueindex(1)); |
| 613 | aux_close(L); /* close it */ |
| 614 | } |
| 615 | return 0; |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | /* }====================================================== */ |
| 620 |
nothing calls this directly
no test coverage detected