示例#1
0
static int io_lines (lua_State *L) {
  if (lua_isnoneornil(L, 1)) {  /* no arguments? */
    lua_pushstring(L, IO_INPUT);
    lua_rawget(L, lua_upvalueindex(1));  /* will iterate over default input */
    return f_lines(L);
  }
  else {
    const char *filename = luaL_checkstring(L, 1);
    FILE **pf = newfile(L);
    *pf = fopen(filename, "r");
    luaL_argcheck(L, *pf, 1,  strerror(errno));
    aux_lines(L, lua_gettop(L), 1);
    return 1;
  }
}
示例#2
0
static int io_lines (lua_State *L) {
    if (lua_isnoneornil(L, 1)) {  /* no arguments? */
        /* will iterate over default input */
        LUA_IO_GETFIELD(IO_INPUT);
        return f_lines(L);
    } else {
        const char *filename = luaL_checkstring(L, 1);
        FILE **pf = newfile(L);
        *pf = fopen(filename, "r");
        if (*pf == NULL)
            fileerror(L, 1, filename);
        aux_lines(L, lua_gettop(L), 1);
        return 1;
    }
}
示例#3
0
static int io_lines(lua_State * L)
{
    if (lua_isnoneornil(L, 1)) {        /* no arguments? */
        /* will iterate over default input */
        lua_rawgeti(L, LUA_ENVIRONINDEX, IO_INPUT);
        return f_lines(L);
    } else {
        const char *filename = luaL_checkstring(L, 1);
        FILE **pf = newfile(L);
        *pf = fopen(filename, "rb");
        if (*pf == NULL)
            fileerror(L, 1, filename);
        else
            recorder_record_input(filename);
        aux_lines(L, lua_gettop(L), 1);
        return 1;
    }
}
示例#4
0
static int io_lines(lua_State *L)
{
    if(lua_isnoneornil(L, 1))     /* no arguments? */
    {
        /* will iterate over default input */
        lua_rawgeti(L, LUA_ENVIRONINDEX, IO_INPUT);
        return f_lines(L);
    }
    else
    {
        const wchar_t *filename = check_utf8_string(L, 1, NULL);
        FILE **pf = newfile(L);
        *pf = _wfopen(filename, L"r");

        if(*pf == NULL)
            fileerror(L, 1, filename);

        aux_lines(L, lua_gettop(L), 1);
        return 1;
    }
}