Example #1
0
File: luazip.c Project: msva/luazip
static int aux_close (lua_State *L) {
  ZZIP_FILE *f = tointernalfile(L, 1);
  int ok = (zzip_fclose(f) == 0);
  if (ok)
    *(ZZIP_FILE **)lua_touserdata(L, 1) = NULL;  /* mark file as closed */
  return ok;
}
Example #2
0
static int ff_seek (lua_State *L) {
  static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
  static const char *const modenames[] = {"set", "cur", "end", NULL};
  ZZIP_FILE *f = tointernalfile(L, 1);
  int op = luaL_checkoption(L, 2, "cur", modenames);
  long offset = luaL_optlong(L, 3, 0);
  luaL_argcheck(L, op != -1, 2, "invalid mode");
  op = zzip_seek(f, offset, mode[op]);
  if (op < 0)
    return pushresult(L, 0, NULL);  /* error */
  else {
    lua_pushnumber(L, zzip_tell(f));
    return 1;
  }
}
Example #3
0
File: luazip.c Project: msva/luazip
static int ff_lines (lua_State *L) {
  tointernalfile(L, 1);  /* check that it's a valid file handle */
  aux_lines(L, 1, 0);
  return 1;
}
Example #4
0
File: luazip.c Project: msva/luazip
static int ff_read (lua_State *L) {
  return g_read(L, tointernalfile(L, 1), 2);
}