aboutsummaryrefslogtreecommitdiff
path: root/src/crypto.h
diff options
context:
space:
mode:
authorame <[email protected]>2024-04-06 16:50:38 -0500
committerame <[email protected]>2024-04-06 16:50:38 -0500
commitd3f3a8a1f3e786965ae473c046db2c34d7d3adb6 (patch)
tree639c6d618b44f0ff2a4fcac9f557b906f37cbec3 /src/crypto.h
parent6dbb6dc2104237299cca414cd3a86256122e4abf (diff)
changed the add metamethod
Diffstat (limited to 'src/crypto.h')
-rw-r--r--src/crypto.h23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/crypto.h b/src/crypto.h
index e58d3a7..03a9728 100644
--- a/src/crypto.h
+++ b/src/crypto.h
@@ -45,11 +45,24 @@ int tp(lua_State*);
#define lua_common_hash_init_update(hashname, luaname) lua_common_hash_init(hashname, luaname) lua_common_hash_update(hashname, luaname)
#define lua_common_hash_init(hashname, luaname) lua_common_hash_init_ni(hashname, luaname, hashname##_init())
+#define common_hash_clone(hashname) lua_common_hash_clone(hashname, hashname)
+#define lua_common_hash_clone(hashname, luaname) lua_common_hash_clone_oargs(hashname, luaname, l_##luaname##_init(L))
+#define lua_common_hash_clone_oargs(hashname, luaname, oinit)\
+int l_##luaname##_clone(lua_State* L){\
+ struct hashname##_hash* a = (struct hashname##_hash*)lua_touserdata(L, -1);\
+ oinit;\
+ struct hashname##_hash* b = (struct hashname##_hash*)lua_touserdata(L, -1);\
+ *b = *a;\
+ return 1;\
+}
+
#define lua_common_hash_meta(luaname)\
int _##luaname##_hash_add(lua_State*L){\
- l_##luaname##_update(L);\
lua_pushvalue(L, 1);\
- return l_##luaname##_final(L);\
+ l_##luaname##_clone(L);\
+ lua_pushvalue(L, -1);\
+ lua_pushvalue(L, 2);\
+ return l_##luaname##_update(L);\
}\
int _##luaname##_common_hash(lua_State* L){\
lua_newtable(L);\
@@ -84,13 +97,13 @@ int _##luaname##_common_hash(lua_State* L){\
#define lua_common_hash_update(hashname, luaname)\
int l_##luaname##_update(lua_State* L){\
- struct hashname##_hash* a = (struct hashname##_hash*)lua_touserdata(L, 1);\
+ struct hashname##_hash* a = (struct hashname##_hash*)lua_touserdata(L, -2);\
size_t len = 0;\
- uint8_t* b = (uint8_t*)luaL_checklstring(L, 2, &len);\
+ uint8_t* b = (uint8_t*)luaL_checklstring(L, -1, &len);\
\
hashname##_update(b, len, a);\
\
- lua_pushvalue(L, 1);\
+ lua_pushvalue(L, -2);\
return 1;\
}