MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / io_lines

Function io_lines

3rd/lua-5.4.3/src/liolib.c:386–410  ·  view source on GitHub ↗

** Return an iteration function for 'io.lines'. If file has to be ** closed, also returns the file itself as a second result (to be ** closed as the state at the exit of a generic for). */

Source from the content-addressed store, hash-verified

384** closed as the state at the exit of a generic for).
385*/
386static int io_lines (lua_State *L) {
387 int toclose;
388 if (lua_isnone(L, 1)) lua_pushnil(L); /* at least one argument */
389 if (lua_isnil(L, 1)) { /* no file name? */
390 lua_getfield(L, LUA_REGISTRYINDEX, IO_INPUT); /* get default input */
391 lua_replace(L, 1); /* put it at index 1 */
392 tofile(L); /* check that it's a valid file handle */
393 toclose = 0; /* do not close it after iteration */
394 }
395 else { /* open a new file */
396 const char *filename = luaL_checkstring(L, 1);
397 opencheck(L, filename, "r");
398 lua_replace(L, 1); /* put file at index 1 */
399 toclose = 1; /* close it after iteration */
400 }
401 aux_lines(L, toclose); /* push iteration function */
402 if (toclose) {
403 lua_pushnil(L); /* state */
404 lua_pushnil(L); /* control */
405 lua_pushvalue(L, 1); /* file is the to-be-closed variable (4th result) */
406 return 4;
407 }
408 else
409 return 1;
410}
411
412
413/*

Callers

nothing calls this directly

Calls 6

lua_pushnilFunction · 0.85
lua_getfieldFunction · 0.85
tofileFunction · 0.85
opencheckFunction · 0.85
aux_linesFunction · 0.85
lua_pushvalueFunction · 0.85

Tested by

no test coverage detected