From 57d67eb910aa765df2495df9f625bfc00436014b Mon Sep 17 00:00:00 2001 From: ame Date: Wed, 27 Mar 2024 13:34:34 -0500 Subject: fixed a few hashes --- src/hash/adler.c | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) (limited to 'src/hash/adler.c') diff --git a/src/hash/adler.c b/src/hash/adler.c index 7d922e9..c6b4d7f 100644 --- a/src/hash/adler.c +++ b/src/hash/adler.c @@ -23,35 +23,7 @@ uint32_t adler32(uint8_t* aa, size_t len){ return adler32_final(&dig); } -int l_adler32_init(lua_State* L){ - lua_newtable(L); - int t = lua_gettop(L); - - struct adler32_hash* a = (struct adler32_hash*)lua_newuserdata(L, sizeof * a); - int ud = lua_gettop(L); - *a = adler32_init(); - - luaI_tsetv(L, t, "ud", ud); - luaI_tsetcf(L, t, "update", l_adler32_update); - luaI_tsetcf(L, t, "final", l_adler32_final); - - lua_pushvalue(L, t); - return 1; -} - -int l_adler32_update(lua_State* L){ - lua_pushstring(L, "ud"); - lua_gettable(L, 1); - - struct adler32_hash* a = (struct adler32_hash*)lua_touserdata(L, -1); - size_t len = 0; - uint8_t* b = (uint8_t*)luaL_checklstring(L, 2, &len); - - adler32_update(b, len, a); - - lua_pushvalue(L, 1); - return 1; -} +common_hash_init_update(adler32); int l_adler32_final(lua_State* L){ lua_pushstring(L, "ud"); @@ -66,6 +38,7 @@ int l_adler32_final(lua_State* L){ } int l_adler32(lua_State* L){ + if(lua_gettop(L) == 0) return l_adler32_init(L); size_t len = 0; uint8_t* a = (uint8_t*)luaL_checklstring(L, 1, &len); -- cgit v1.2.3