diff --git a/CMakeLists.txt b/CMakeLists.txt index b191370..3200dfb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ CMAKE_MINIMUM_REQUIRED (VERSION 2.6) # Define how to build archive.so: INCLUDE_DIRECTORIES(${LIBARCHIVE_INCLUDE_DIR} ${LUA_INCLUDE_DIR}) ADD_LIBRARY(cmod_archive MODULE - ar.c ar_write.c ar_registry.c ar_read.c ar_entry.c archive.def) + ar.c ar_write.c ar_registry.c ar_read.c ar_entry.c ar.h archive.def) SET_TARGET_PROPERTIES(cmod_archive PROPERTIES PREFIX "") SET_TARGET_PROPERTIES(cmod_archive PROPERTIES OUTPUT_NAME archive) TARGET_LINK_LIBRARIES(cmod_archive ${LUA_LIBRARIES} ${LIBARCHIVE_LIBRARY}) diff --git a/ar.c b/ar.c index bc7739c..24f3b8f 100644 --- a/ar.c +++ b/ar.c @@ -6,6 +6,7 @@ #include #include +#include "ar.h" #include "ar_registry.h" #include "ar_read.h" #include "ar_write.h" @@ -39,7 +40,7 @@ static int ar_version(lua_State *L) { ////////////////////////////////////////////////////////////////////// LUALIB_API int luaopen_archive(lua_State *L) { - static luaL_reg fns[] = { + static luaL_Reg fns[] = { { "version", ar_version }, { NULL, NULL } }; diff --git a/ar.h b/ar.h new file mode 100644 index 0000000..f3a5144 --- /dev/null +++ b/ar.h @@ -0,0 +1,10 @@ +#if !defined LUA_VERSION_NUM +/* Lua 5.0 */ +#define luaL_Reg luaL_reg +#endif + +#if LUA_VERSION_NUM <= 501 +/* Lua 5.1 or older */ +#define lua_setuservalue lua_setfenv +#define lua_getuservalue lua_getfenv +#endif diff --git a/ar_entry.c b/ar_entry.c index 72056ac..19265dd 100644 --- a/ar_entry.c +++ b/ar_entry.c @@ -7,6 +7,7 @@ #include #include +#include "ar.h" #include "ar_entry.h" #define err(...) (luaL_error(L, __VA_ARGS__)) @@ -430,13 +431,13 @@ static int ar_entry_pathname(lua_State *L) { ////////////////////////////////////////////////////////////////////// int ar_entry_init(lua_State *L) { - static luaL_reg fns[] = { + static luaL_Reg fns[] = { { "entry", ar_entry }, { "_entry_ref_count", ar_ref_count }, { NULL, NULL } }; // So far there are no methods on the entry objects. - static luaL_reg m_fns[] = { + static luaL_Reg m_fns[] = { { "fflags", ar_entry_fflags }, { "dev", ar_entry_dev }, { "ino", ar_entry_ino }, diff --git a/ar_read.c b/ar_read.c index 39e0812..4c0ee4c 100644 --- a/ar_read.c +++ b/ar_read.c @@ -10,6 +10,7 @@ #include #include +#include "ar.h" #include "ar_read.h" #include "ar_entry.h" #include "ar_registry.h" @@ -85,13 +86,13 @@ static int ar_read(lua_State *L) { { NULL, NULL } }; static named_setter compression_names[] = { - { "all", archive_read_support_compression_all }, - { "bzip2", archive_read_support_compression_bzip2 }, - { "compress", archive_read_support_compression_compress }, - { "gzip", archive_read_support_compression_gzip }, - { "lzma", archive_read_support_compression_lzma }, - { "none", archive_read_support_compression_none }, - { "xz", archive_read_support_compression_xz }, + { "all", archive_read_support_filter_all }, + { "bzip2", archive_read_support_filter_bzip2 }, + { "compress", archive_read_support_filter_compress }, + { "gzip", archive_read_support_filter_gzip }, + { "lzma", archive_read_support_filter_lzma }, + { "none", archive_read_support_filter_none }, + { "xz", archive_read_support_filter_xz }, { NULL, NULL } }; @@ -113,12 +114,12 @@ static int ar_read(lua_State *L) { lua_getfield(L, 1, "reader"); // {ud}, {fenv}, fn if ( ! lua_isfunction(L, -1) ) err("MissingArgument: required parameter 'reader' must be a function"); lua_setfield(L, -2, "reader"); // {ud}, {fenv} - lua_setfenv(L, -2); // {ud} + lua_setuservalue(L, -2); // {ud} // Do it the easy way for now... perhaps in the future we will // have a parameter to support toggling which algorithms are // supported: - if ( ARCHIVE_OK != archive_read_support_compression_all(*self_ref) ) { + if ( ARCHIVE_OK != archive_read_support_filter_all(*self_ref) ) { err("archive_read_support_compression_all: %s", archive_error_string(*self_ref)); } if ( ARCHIVE_OK != archive_read_support_format_all(*self_ref) ) { @@ -178,7 +179,7 @@ static int ar_read(lua_State *L) { // the index to the argument for which to pass to reader exists. If // idx is zero, nil is passed into reader. static void ar_read_get_reader(lua_State *L, int self_idx) { - lua_getfenv(L, self_idx); // {env} + lua_getuservalue(L, self_idx); // {env} lua_pushliteral(L, "reader"); // {env}, "reader" lua_rawget(L, -2); // {env}, reader lua_insert(L, -2); // reader, {env} @@ -197,7 +198,7 @@ static int ar_read_destroy(lua_State *L) { if ( ARCHIVE_OK != archive_read_close(*self_ref) ) { lua_pushfstring(L, "archive_read_close: %s", archive_error_string(*self_ref)); - archive_read_finish(*self_ref); + archive_read_free(*self_ref); __ref_count--; *self_ref = NULL; lua_error(L); @@ -210,8 +211,8 @@ static int ar_read_destroy(lua_State *L) { lua_call(L, 2, 1); // {self}, result } - if ( ARCHIVE_OK != archive_read_finish(*self_ref) ) { - luaL_error(L, "archive_read_finish: %s", archive_error_string(*self_ref)); + if ( ARCHIVE_OK != archive_read_free(*self_ref) ) { + luaL_error(L, "archive_read_free: %s", archive_error_string(*self_ref)); } __ref_count--; *self_ref = NULL; @@ -248,7 +249,7 @@ static __LA_SSIZE_T ar_read_cb(struct archive * self, // We directly return the raw internal buffer, so we need to keep // a reference around: - lua_getfenv(L, -2); // {ud}, result, {fenv} + lua_getuservalue(L, -2); // {ud}, result, {fenv} lua_insert(L, -2); // {ud}, {fenv}, result lua_pushliteral(L, "read_buffer"); // {ud}, {fenv}, result, "read_buffer" lua_insert(L, -2); // {ud}, {fenv}, "read_buffer", result @@ -317,12 +318,12 @@ static int ar_read_data(lua_State *L) { // of the stack, and the archive{read} metatable is registered. ////////////////////////////////////////////////////////////////////// int ar_read_init(lua_State *L) { - static luaL_reg fns[] = { + static luaL_Reg fns[] = { { "read", ar_read }, { "_read_ref_count", ar_ref_count }, { NULL, NULL } }; - static luaL_reg m_fns[] = { + static luaL_Reg m_fns[] = { { "next_header", ar_read_next_header }, { "headers", ar_read_headers }, { "data", ar_read_data }, diff --git a/ar_write.c b/ar_write.c index 95ed17e..129a7bc 100644 --- a/ar_write.c +++ b/ar_write.c @@ -10,6 +10,7 @@ #include #include +#include "ar.h" #include "ar_write.h" #include "ar_entry.h" #include "ar_registry.h" @@ -83,7 +84,7 @@ static int ar_write(lua_State *L) { err("MissingArgument: required parameter 'writer' must be a function"); } lua_setfield(L, -2, "writer"); - lua_setfenv(L, -2); // {ud} + lua_setuservalue(L, -2); // {ud} // Extract various fields and prepare the archive: lua_getfield(L, 1, "bytes_per_block"); @@ -154,11 +155,11 @@ static int ar_write(lua_State *L) { const char *name; int (*setter)(struct archive *); } names[] = { - { "bzip2", archive_write_set_compression_bzip2 }, - { "compress", archive_write_set_compression_compress }, - { "gzip", archive_write_set_compression_gzip }, - { "lzma", archive_write_set_compression_lzma }, - { "xz", archive_write_set_compression_xz }, + { "bzip2", archive_write_add_filter_bzip2 }, + { "compress", archive_write_add_filter_compress }, + { "gzip", archive_write_add_filter_gzip }, + { "lzma", archive_write_add_filter_lzma }, + { "xz", archive_write_add_filter_xz }, { NULL, NULL } }; int idx = 0; @@ -196,7 +197,7 @@ static int ar_write(lua_State *L) { // the index to the argument for which to pass to writer exists. If // idx is zero, nil is passed into writer. static void ar_write_get_writer(lua_State *L, int self_idx) { - lua_getfenv(L, self_idx); // {env} + lua_getuservalue(L, self_idx); // {env} lua_pushliteral(L, "writer"); // {env}, "writer" lua_rawget(L, -2); // {env}, writer lua_insert(L, -2); // writer, {env} @@ -215,7 +216,7 @@ static int ar_write_destroy(lua_State *L) { if ( ARCHIVE_OK != archive_write_close(*self_ref) ) { lua_pushfstring(L, "archive_write_close: %s", archive_error_string(*self_ref)); - archive_write_finish(*self_ref); + archive_write_free(*self_ref); __ref_count--; *self_ref = NULL; lua_error(L); @@ -228,8 +229,8 @@ static int ar_write_destroy(lua_State *L) { lua_call(L, 2, 1); // {self}, result } - if ( ARCHIVE_OK != archive_write_finish(*self_ref) ) { - luaL_error(L, "archive_write_finish: %s", archive_error_string(*self_ref)); + if ( ARCHIVE_OK != archive_write_free(*self_ref) ) { + luaL_error(L, "archive_write_free: %s", archive_error_string(*self_ref)); } __ref_count--; *self_ref = NULL; @@ -303,7 +304,7 @@ static int ar_write_data(lua_State *L) { data = lua_tolstring(L, 2, &len); - archive_write_data(self, data, len); + wrote = archive_write_data(self, data, len); if ( -1 == wrote ) { err("archive_write_data: %s", archive_error_string(self)); } @@ -319,12 +320,12 @@ static int ar_write_data(lua_State *L) { // of the stack, and the archive{write} metatable is registered. ////////////////////////////////////////////////////////////////////// int ar_write_init(lua_State *L) { - static luaL_reg fns[] = { + static luaL_Reg fns[] = { { "write", ar_write }, { "_write_ref_count", ar_ref_count }, { NULL, NULL } }; - static luaL_reg m_fns[] = { + static luaL_Reg m_fns[] = { { "header", ar_write_header }, { "data", ar_write_data }, { "close", ar_write_destroy }, diff --git a/test.lua b/test.lua index 93b147d..3c1f4bf 100644 --- a/test.lua +++ b/test.lua @@ -74,7 +74,7 @@ function test_basic() -- Test creating our own "normal" entry: local normal_entry = { - fflags="nosappnd,dump,archive", + fflags="nosappnd,dump", dev=200, ino=1000, mode=0x80FF,