Ejemplo n.º 1
0
static int io_readline (lua_State *L) {
  FILE *f = *(FILE **)lua_touserdata(L, lua_upvalueindex(1));
  int sucess;
  if (f == NULL)  /* file is already closed? */
    luaL_error(L, "file is already closed");
  sucess = read_line(L, f);
  if (ferror(f))
    return luaL_error(L, "%s", strerror(errno));
  if (sucess) return 1;
  else {  /* EOF */
    if (lua_toboolean(L, lua_upvalueindex(2))) {  /* generator created file? */
      lua_settop(L, 0);
      lua_pushvalue(L, lua_upvalueindex(1));
      aux_close(L);  /* close it */
    }
    return 0;
  }
}
Ejemplo n.º 2
0
static int io_readline (lua_State *L) {
  int *pf = (int *)lua_touserdata(L, lua_upvalueindex(1));
  int sucess;
  if (pf == NULL || *pf == FS_OPEN_OK - 1){  /* file is already closed? */
    luaL_error(L, "file is already closed");
    return 0;
  }
  sucess = read_line(L, *pf);
  if (fs_error(*pf))
    return luaL_error(L, "err(%d)", fs_error(*pf));
  if (sucess) return 1;
  else {  /* EOF */
    if (lua_toboolean(L, lua_upvalueindex(2))) {  /* generator created file? */
      lua_settop(L, 0);
      lua_pushvalue(L, lua_upvalueindex(1));
      aux_close(L);  /* close it */
    }
    return 0;
  }
}
Ejemplo n.º 3
0
static int io_close (lua_State *L) {
  if (lua_isnone(L, 1))
    lua_rawgeti(L, LUA_ENVIRONINDEX, IO_OUTPUT);
  tofile(L);  /* make sure argument is a file */
  return aux_close(L);
}
Ejemplo n.º 4
0
static int f_gc(lua_State *L) {
	LStream *p = tolstream(L);
	if (!isclosed(p) && p->f != NULL)
		aux_close(L);  /* ignore closed and incompletely open files */
	return 0;
}
Ejemplo n.º 5
0
static int io_close(lua_State *L) {
	if (lua_isnone(L, 1))  /* no argument? */
		lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT);  /* use standard output */
	tofile(L);  /* make sure argument is an open stream */
	return aux_close(L);
}
Ejemplo n.º 6
0
static int io_gc (lua_State *L) {
  FILE **f = topfile(L, 1);
  if (*f != NULL)  /* ignore closed files */
    aux_close(L);
  return 0;
}
Ejemplo n.º 7
0
static int io_close (lua_State *L) {
    if (lua_isnone(L, 1))
        LUA_IO_GETFIELD(IO_OUTPUT);
    tofile(L);  /* make sure argument is a file */
    return aux_close(L);
}
Ejemplo n.º 8
0
Archivo: luazip.c Proyecto: msva/luazip
static int ff_gc (lua_State *L) {
  ZZIP_FILE**f = topinternalfile(L, 1);
  if (*f != NULL)  /* ignore closed files */
    aux_close(L);
  return 0;
}
Ejemplo n.º 9
0
Archivo: luazip.c Proyecto: msva/luazip
static int ff_close (lua_State *L) {
  return pushresult(L, aux_close(L), NULL);
}
Ejemplo n.º 10
0
static int io_gc (lua_State *L) {
  FileHandle *fh = topfile(L, 1);
  if (fh->f != NULL)  /* ignore closed files */
    aux_close(L);
  return 0;
}