MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / io_readline

Function io_readline

lib/lua/src/liolib.c:633–659  ·  view source on GitHub ↗

** Iteration function for 'lines'. */

Source from the content-addressed store, hash-verified

631** Iteration function for 'lines'.
632*/
633static int io_readline (lua_State *L) {
634 LStream *p = (LStream *)lua_touserdata(L, lua_upvalueindex(1));
635 int i;
636 int n = (int)lua_tointeger(L, lua_upvalueindex(2));
637 if (isclosed(p)) /* file is already closed? */
638 return luaL_error(L, "file is already closed");
639 lua_settop(L , 1);
640 luaL_checkstack(L, n, "too many arguments");
641 for (i = 1; i <= n; i++) /* push arguments to 'g_read' */
642 lua_pushvalue(L, lua_upvalueindex(3 + i));
643 n = g_read(L, p->f, 2); /* 'n' is number of results */
644 lua_assert(n > 0); /* should return at least a nil */
645 if (lua_toboolean(L, -n)) /* read at least one value? */
646 return n; /* return them */
647 else { /* first result is false: EOF or error */
648 if (n > 1) { /* is there error information? */
649 /* 2nd result is error message */
650 return luaL_error(L, "%s", lua_tostring(L, -n + 1));
651 }
652 if (lua_toboolean(L, lua_upvalueindex(3))) { /* generator created file? */
653 lua_settop(L, 0); /* clear stack */
654 lua_pushvalue(L, lua_upvalueindex(1)); /* push file at index 1 */
655 aux_close(L); /* close it */
656 }
657 return 0;
658 }
659}
660
661/* }====================================================== */
662

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected