/* 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).  */
static int io_lines(lua_State *L)
/* 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).  */
static int io_lines(lua_State *L)
{
    lua_getfield(L, LUA_REGISTRYINDEX, IO_INPUT);
    lua_replace(L, 1);
    tofile(L);
    toclose = 0;
  }
  else {
    const char *filename = luaL_checkstring(L, 1);
    opencheck(L, filename, "r");
    lua_replace(L, 1);
    toclose = 1;
  }
  aux_lines(L, toclose);
  if (toclose) {
    lua_pushnil(L);
    lua_pushnil(L);
    lua_pushvalue(L, 1);
    return 4;
  }
  else
    return 1;
}