aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatarLibravatar William Ahern <william@Williams-MacBook-Air.local> 2012-10-10 16:46:28 -0700
committerLibravatarLibravatar William Ahern <william@Williams-MacBook-Air.local> 2012-10-10 16:46:28 -0700
commit7bdf2557bbf7267542604567a0db809657b54d97 (patch)
tree13ba523c6f40b70536bc4ca8c4cc661948f831a8
parentac93581c90d8a1612ce01e3a308d572f98002924 (diff)
downloadluaossl-7bdf2557bbf7267542604567a0db809657b54d97.tar.gz
luaossl-7bdf2557bbf7267542604567a0db809657b54d97.tar.bz2
luaossl-7bdf2557bbf7267542604567a0db809657b54d97.zip
-n
fix compile for LuaJIT
-rw-r--r--Makefile2
-rw-r--r--compat52.h50
-rw-r--r--openssl.c7
3 files changed, 58 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index c6f7e4d..609f09c 100644
--- a/Makefile
+++ b/Makefile
@@ -40,7 +40,7 @@ all: openssl.so
openssl.so: openssl.o
$(CC) -o $@ $^ $(SOFLAGS) $(LDFLAGS)
-openssl.o: openssl.c
+openssl.o: openssl.c compat52.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
diff --git a/compat52.h b/compat52.h
new file mode 100644
index 0000000..c674f13
--- /dev/null
+++ b/compat52.h
@@ -0,0 +1,50 @@
+
+
+static void luaL_setmetatable(lua_State *L, const char *tname) {
+ luaL_getmetatable(L, tname);
+ lua_setmetatable(L, -2);
+} /* luaL_setmetatable() */
+
+
+static int lua_absindex(lua_State *L, int idx) {
+ return (idx > 0 || idx <= LUA_REGISTRYINDEX)? idx : lua_gettop(L) + idx + 1;
+} /* lua_absindex() */
+
+
+static void *luaL_testudata(lua_State *L, int arg, const char *tname) {
+ void *p = lua_touserdata(L, arg);
+ int eq;
+
+ if (!p || !lua_getmetatable(L, arg))
+ return 0;
+
+ luaL_getmetatable(L, tname);
+ eq = lua_rawequal(L, -2, -1);
+ lua_pop(L, 2);
+
+ return (eq)? p : 0;
+} /* luaL_testudate() */
+
+
+static void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup) {
+ int i, t = lua_absindex(L, -1 - nup);
+
+ for (; l->name; l++) {
+ for (i = 0; i < nup; i++)
+ lua_pushvalue(L, -nup);
+ lua_pushcclosure(L, l->func, nup);
+ lua_setfield(L, t, l->name);
+ }
+
+ return lua_pop(L, nup);
+} /* luaL_setfuncs() */
+
+
+#define luaL_newlibtable(L, l) \
+ lua_createtable(L, 0, (sizeof (l) / sizeof *(l)) - 1)
+
+#define luaL_newlib(L, l) \
+ (luaL_newlibtable((L), (l)), luaL_setfuncs((L), (l), 0))
+
+
+
diff --git a/openssl.c b/openssl.c
index c0196bd..4ab0688 100644
--- a/openssl.c
+++ b/openssl.c
@@ -52,6 +52,9 @@
#include <lualib.h>
#include <lauxlib.h>
+#if LUA_VERSION_NUM < 502
+#include "compat52.h"
+#endif
#define BIGNUM_CLASS "OpenSSL Bignum"
#define PUBKEY_CLASS "OpenSSL Pubkey"
@@ -1665,7 +1668,11 @@ static int xc_digest(lua_State *L) {
luaL_Buffer B;
unsigned i;
+#if LUA_VERSION_NUM < 502
+ luaL_buffinit(L, &B);
+#else
luaL_buffinitsize(L, &B, 2 * len);
+#endif
for (i = 0; i < len; i++) {
luaL_addchar(&B, x[0x0f & (md[i] >> 4)]);