MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / io_readline

Function io_readline

extlibs/lua/src/liolib.c:615–641  ·  view source on GitHub ↗

** Iteration function for 'lines'. */

Source from the content-addressed store, hash-verified

613** Iteration function for 'lines'.
614*/
615static int io_readline (lua_State *L) {
616 LStream *p = (LStream *)lua_touserdata(L, lua_upvalueindex(1));
617 int i;
618 int n = (int)lua_tointeger(L, lua_upvalueindex(2));
619 if (isclosed(p)) /* file is already closed? */
620 return luaL_error(L, "file is already closed");
621 lua_settop(L , 1);
622 luaL_checkstack(L, n, "too many arguments");
623 for (i = 1; i <= n; i++) /* push arguments to 'g_read' */
624 lua_pushvalue(L, lua_upvalueindex(3 + i));
625 n = g_read(L, p->f, 2); /* 'n' is number of results */
626 lua_assert(n > 0); /* should return at least a nil */
627 if (lua_toboolean(L, -n)) /* read at least one value? */
628 return n; /* return them */
629 else { /* first result is false: EOF or error */
630 if (n > 1) { /* is there error information? */
631 /* 2nd result is error message */
632 return luaL_error(L, "%s", lua_tostring(L, -n + 1));
633 }
634 if (lua_toboolean(L, lua_upvalueindex(3))) { /* generator created file? */
635 lua_settop(L, 0); /* clear stack */
636 lua_pushvalue(L, lua_upvalueindex(1)); /* push file at index 1 */
637 aux_close(L); /* close it */
638 }
639 return 0;
640 }
641}
642
643/* }====================================================== */
644

Callers

nothing calls this directly

Calls 8

lua_touserdataFunction · 0.85
luaL_errorFunction · 0.85
lua_settopFunction · 0.85
lua_pushvalueFunction · 0.85
g_readFunction · 0.85
lua_tobooleanFunction · 0.85
aux_closeFunction · 0.85
luaL_checkstackFunction · 0.70

Tested by

no test coverage detected