From a63e737bd12e466937223c848387d0b704f02e31 Mon Sep 17 00:00:00 2001 From: William Ahern Date: Fri, 24 Jun 2016 19:00:25 -0700 Subject: refactor and add ashb's regression test for #53 --- src/GNUmakefile | 1 + src/openssl.auxlib.lua | 21 +++++++++++++++++++++ src/openssl.x509.altname.lua | 3 ++- src/openssl.x509.name.lua | 3 ++- 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src/openssl.auxlib.lua (limited to 'src') diff --git a/src/GNUmakefile b/src/GNUmakefile index 3aff30a..f0eefde 100644 --- a/src/GNUmakefile +++ b/src/GNUmakefile @@ -88,6 +88,7 @@ LUAC$(1)_$(d) = $$(or $$(call LUAPATH_$(d), $(1), luac), true) MODS$(1)_$(d) = \ $$(DESTDIR)$(2)/_openssl.so \ $$(DESTDIR)$(3)/openssl.lua \ + $$(DESTDIR)$(3)/openssl/auxlib.lua \ $$(DESTDIR)$(3)/openssl/bignum.lua \ $$(DESTDIR)$(3)/openssl/pkey.lua \ $$(DESTDIR)$(3)/openssl/pubkey.lua \ diff --git a/src/openssl.auxlib.lua b/src/openssl.auxlib.lua new file mode 100644 index 0000000..4f00c25 --- /dev/null +++ b/src/openssl.auxlib.lua @@ -0,0 +1,21 @@ +local auxlib = {} + +if _VERSION == "Lua 5.1" then + local _pairs = pairs + + function auxlib.pairs(t) + if type(t) == "userdata" then + local mt = getmetatable(t) + + if mt and mt.__pairs then + return mt.__pairs(t) + else + return _pairs(t) + end + end + end +else + auxlib.pairs = pairs +end + +return auxlib diff --git a/src/openssl.x509.altname.lua b/src/openssl.x509.altname.lua index 66f16e7..e8222a0 100644 --- a/src/openssl.x509.altname.lua +++ b/src/openssl.x509.altname.lua @@ -1,9 +1,10 @@ local altname = require"_openssl.x509.altname" +local auxlib = require"openssl.auxlib" altname.interpose("__tostring", function (self) local t = { } - for k, v in pairs(self) do + for k, v in auxlib.pairs(self) do t[#t + 1] = k .. ":" .. v end diff --git a/src/openssl.x509.name.lua b/src/openssl.x509.name.lua index a531502..f33339a 100644 --- a/src/openssl.x509.name.lua +++ b/src/openssl.x509.name.lua @@ -1,9 +1,10 @@ local name = require"_openssl.x509.name" +local auxlib = require"openssl.auxlib" name.interpose("__tostring", function (self) local t = { } - for k, v in pairs(self) do + for k, v in auxlib.pairs(self) do t[#t + 1] = k .. "=" .. v end -- cgit v1.2.3-59-g8ed1b