static int ar_entry_birthtime(lua_State *L) { struct archive_entry* self = *ar_entry_check(L, 1); int is_set; int num_results; if ( NULL == self ) return 0; is_set = ( lua_gettop(L) >= 2 ); num_results = 0; if ( archive_entry_birthtime_is_set(self) ) { num_results = 2; lua_pushnumber(L, archive_entry_birthtime(self)); lua_pushnumber(L, archive_entry_birthtime_nsec(self)); } if ( is_set ) { if ( lua_isnil(L, 2) ) { archive_entry_unset_birthtime(self); } else if ( lua_istable(L, 2) ) { lua_rawgeti(L, 2, 1); lua_rawgeti(L, 2, 2); archive_entry_set_birthtime(self, lua_tonumber(L, -2), lua_tonumber(L, -1)); } else { archive_entry_set_birthtime(self, lua_tonumber(L, 2), lua_tonumber(L, 3)); } } return num_results; }
static int ar_entry_destroy(lua_State *L) { struct archive_entry** self_ref = ar_entry_check(L, 1); if ( *self_ref != NULL ) { __ref_count--; archive_entry_free(*self_ref); *self_ref = NULL; } return 0; }
static int ar_entry_dev(lua_State *L) { struct archive_entry* self = *ar_entry_check(L, 1); int is_set; if ( NULL == self ) return 0; is_set = ( lua_gettop(L) == 2 ); lua_pushnumber(L, archive_entry_dev(self)); if ( is_set ) { archive_entry_set_dev(self, lua_tonumber(L, 2)); } return 1; }
static int ar_entry_pathname(lua_State *L) { struct archive_entry* self = *ar_entry_check(L, 1); int is_set; if ( NULL == self ) return 0; is_set = ( lua_gettop(L) == 2 ); lua_pushstring(L, archive_entry_pathname(self)); if ( is_set ) { archive_entry_copy_pathname(self, lua_tostring(L, 2)); } return 1; }
static int ar_entry_mode(lua_State *L) { struct archive_entry* self = *ar_entry_check(L, 1); int is_set; if ( NULL == self ) return 0; is_set = ( lua_gettop(L) == 2 ); lua_pushnumber(L, archive_entry_mode(self)); if ( is_set ) { __LA_MODE_T mode = lua_tonumber(L, 2); archive_entry_set_mode(self, mode); } return 1; }
static int ar_entry_fflags(lua_State *L) { struct archive_entry* self = *ar_entry_check(L, 1); int is_set; if ( NULL == self ) return 0; is_set = ( lua_gettop(L) == 2 ); lua_pushstring(L, archive_entry_fflags_text(self)); if ( is_set ) { const char* invalid = archive_entry_copy_fflags_text(self, lua_tostring(L, 2)); if ( NULL != invalid ) { err("InvalidFFlag: '%s' is not a known fflag", invalid); } } return 1; }
static int ar_read_next_header(lua_State *L) { struct archive_entry* entry; struct archive* self = *ar_read_check(L, 1); // {ud} int result; if ( NULL == self ) err("NULL archive{read}!"); lua_pushcfunction(L, ar_entry); // {ud}, ar_entry lua_call(L, 0, 1); // {ud}, header entry = *ar_entry_check(L, -1); result = archive_read_next_header2(self, entry); if ( ARCHIVE_EOF == result ) { lua_pop(L, 1); // {ud} lua_pushnil(L); // {ud}, nil } else if ( ARCHIVE_OK != result ) { err("archive_read_next_header2: %s", archive_error_string(self)); } return 1; }
static int ar_entry_size(lua_State *L) { struct archive_entry* self = *ar_entry_check(L, 1); int is_set; if ( NULL == self ) return 0; is_set = ( lua_gettop(L) == 2 ); if ( archive_entry_size_is_set(self) ) { lua_pushnumber(L, archive_entry_size(self)); } else { lua_pushnil(L); } if ( is_set ) { if ( lua_isnil(L, 2) ) { archive_entry_unset_size(self); } else { archive_entry_set_size(self, lua_tonumber(L, 2)); } } return 1; }
static int ar_write_header(lua_State *L) { struct archive* self; struct archive_entry* entry; const char* pathname; self = *ar_write_check(L, 1); if ( NULL == self ) err("NULL archive{write}!"); entry = *ar_entry_check(L, 2); if ( NULL == entry ) err("NULL archive{entry}!"); // Give a nicer error message: pathname = archive_entry_pathname(entry); if ( NULL == pathname || '\0' == *pathname ) { err("InvalidEntry: 'pathname' field must be set"); } if ( ARCHIVE_OK != archive_write_header(self, entry) ) { err("archive_write_header: %s", archive_error_string(self)); } return 0; }