Skip to content

Commit

Permalink
Merge pull request #322 from evo-lua/miniz-input-ordering
Browse files Browse the repository at this point in the history
Reorder the parameters of miniz checksum APIs
  • Loading branch information
Duckwhale committed Oct 8, 2023
2 parents c9c3609 + a915d5d commit 61f5ab3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions Runtime/Bindings/lminiz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,18 +365,18 @@ static int ltdefl(lua_State* L) {
}

static int lmz_adler32(lua_State* L) {
mz_ulong adler = luaL_optinteger(L, 1, 0);
mz_ulong adler = luaL_optinteger(L, 2, 0);
size_t buf_len = 0;
const unsigned char* ptr = reinterpret_cast<const unsigned char*>(luaL_optlstring(L, 2, NULL, &buf_len));
const unsigned char* ptr = reinterpret_cast<const unsigned char*>(luaL_optlstring(L, 1, NULL, &buf_len));
adler = mz_adler32(adler, ptr, buf_len);
lua_pushinteger(L, adler);
return 1;
}

static int lmz_crc32(lua_State* L) {
mz_ulong crc32 = luaL_optinteger(L, 1, 0);
mz_ulong crc32 = luaL_optinteger(L, 2, 0);
size_t buf_len = 0;
const unsigned char* ptr = reinterpret_cast<const unsigned char*>(luaL_optlstring(L, 2, NULL, &buf_len));
const unsigned char* ptr = reinterpret_cast<const unsigned char*>(luaL_optlstring(L, 1, NULL, &buf_len));
crc32 = mz_crc32(crc32, ptr, buf_len);
lua_pushinteger(L, crc32);
return 1;
Expand Down
16 changes: 8 additions & 8 deletions Tests/BDD/miniz-library.spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,33 @@ describe("miniz", function()

describe("adler32", function()
it("should return a checksum for the given input string", function()
local checksum = miniz.adler32(1, "Hello world")
local checksum = miniz.adler32("Hello world", 1)
assertEquals(checksum, 413860925)
end)

it("should generate the same checksum regardless of how it is computed", function()
local checksum1 = miniz.adler32(1, "one two")
local checksum1 = miniz.adler32("one two", 1)
assertEquals(checksum1, 181797565)

local checksum2 = miniz.adler32(1, "one")
checksum2 = miniz.adler32(checksum2, " two")
local checksum2 = miniz.adler32("one", 1)
checksum2 = miniz.adler32(" two", checksum2)

assertEquals(checksum1, checksum2)
end)
end)

describe("crc32", function()
it("should return a checksum for the given input string", function()
local checksum = miniz.crc32(0, "Hello world")
local checksum = miniz.crc32("Hello world")
assertEquals(checksum, 2346098258)
end)

it("should generate the same checksum regardless of how it is computed", function()
local checksum1 = miniz.crc32(0, "one two")
local checksum1 = miniz.crc32("one two")
assertEquals(checksum1, 3439823151)

local checksum2 = miniz.crc32(0, "one")
checksum2 = miniz.crc32(checksum2, " two")
local checksum2 = miniz.crc32("one")
checksum2 = miniz.crc32(" two", checksum2)

assertEquals(checksum1, checksum2)
end)
Expand Down

0 comments on commit 61f5ab3

Please sign in to comment.