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

Function io_lines

lib/lua/src/liolib.c:389–413  ·  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

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

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