| 356 | |
| 357 | |
| 358 | static int io_lines (lua_State *L) { |
| 359 | int toclose; |
| 360 | if (lua_isnone(L, 1)) lua_pushnil(L); /* at least one argument */ |
| 361 | if (lua_isnil(L, 1)) { /* no file name? */ |
| 362 | lua_getfield(L, LUA_REGISTRYINDEX, IO_INPUT); /* get default input */ |
| 363 | lua_replace(L, 1); /* put it at index 1 */ |
| 364 | tofile(L); /* check that it's a valid file handle */ |
| 365 | toclose = 0; /* do not close it after iteration */ |
| 366 | } |
| 367 | else { /* open a new file */ |
| 368 | const char *filename = luaL_checkstring(L, 1); |
| 369 | opencheck(L, filename, "r"); |
| 370 | lua_replace(L, 1); /* put file at index 1 */ |
| 371 | toclose = 1; /* close it after iteration */ |
| 372 | } |
| 373 | aux_lines(L, toclose); |
| 374 | return 1; |
| 375 | } |
| 376 | |
| 377 | |
| 378 | /* |
nothing calls this directly
no test coverage detected