예제 #1
0
파일: lgzip.c 프로젝트: leonlee/tome
static int io_lines (lua_State *L) {
  const char *filename = luaL_checkstring(L, 1);
  gzFile *pf = newfile(L);
  *pf = gzopen(filename, "rb");
  luaL_argcheck(L, *pf, 1,  strerror(errno));
  aux_lines(L, lua_gettop(L), 1);
  return 1;
}
예제 #2
0
파일: liolib.c 프로젝트: jjiezheng/pap_full
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;
  }
}
예제 #3
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;
    }
}
예제 #4
0
파일: liolib.c 프로젝트: Allowed/Protheus
static int io_lines(lua_State *L) {
	int toclose;
	if (lua_isnone(L, 1)) lua_pushnil(L);  /* at least one argument */
	if (lua_isnil(L, 1)) {  /* no file name? */
		lua_getfield(L, LUA_REGISTRYINDEX, IO_INPUT);  /* get default input */
		lua_replace(L, 1);  /* put it at index 1 */
		tofile(L);  /* check that it's a valid file handle */
		toclose = 0;  /* do not close it after iteration */
	}
	else {  /* open a new file */
		const char *filename = luaL_checkstring(L, 1);
		opencheck(L, filename, "r");
		lua_replace(L, 1);  /* put file at index 1 */
		toclose = 1;  /* close it after iteration */
	}
	aux_lines(L, toclose);
	return 1;
}
예제 #5
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;
    }
}
예제 #6
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;
    }
}
예제 #7
0
static int f_lines (lua_State *L) {
  tofile(L);  /* check that it's a valid file handle */
  aux_lines(L, 1, 0);
  return 1;
}