From 7ce9f85b3913891b1b2a9135dddccaacbd56010d Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 3 Jun 2024 11:29:15 -0300 Subject: [PATCH] [lua] Fix bug comparing integers and floating points (fix #4516) This bug was introduced in: https://github.com/aseprite/lua/commit/db8284f5fc6f02f8f800c99b84b5e4f640e893ce We've removed the patch in our updated Lua v5.4.6 branch. --- laf | 2 +- src/app/script/engine.cpp | 7 +++++++ tests/scripts/math.lua | 6 ++++++ tests/scripts/save_file_command.lua | 4 ++-- tests/scripts/sprite.lua | 4 ++-- third_party/lua | 2 +- 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/laf b/laf index 4a2e2bb3d..c82fd98b2 160000 --- a/laf +++ b/laf @@ -1 +1 @@ -Subproject commit 4a2e2bb3d91ea5f00d2aac17477bc06434a89e14 +Subproject commit c82fd98b275cb25122106797af00feabc5015c7f diff --git a/src/app/script/engine.cpp b/src/app/script/engine.cpp index bf2814c73..7c46fd1cb 100644 --- a/src/app/script/engine.cpp +++ b/src/app/script/engine.cpp @@ -50,6 +50,13 @@ FILE* lua_user_fopen(const char* fname, return base::open_file_raw(fname, mode); } +FILE* lua_user_freopen(const char* fname, + const char* mode, + FILE* stream) +{ + return base::reopen_file_raw(fname, mode, stream); +} + namespace app { namespace script { diff --git a/tests/scripts/math.lua b/tests/scripts/math.lua index b08b2605a..05a2aee51 100644 --- a/tests/scripts/math.lua +++ b/tests/scripts/math.lua @@ -8,3 +8,9 @@ assert(100 == math.min(100, 200, 300)) assert(300 == math.max(100, 200, 300)) assert(50 == math.fmod(250, 100)) assert(3141 == math.floor(1000*math.pi)) + +-- Add tests for integer <-> number comparisons +assert(math.floor(0.5) == 0) +assert(math.floor(0.5) == 0.0) +assert(math.floor(0.5) ~= 0.5) +assert(math.floor(0.5)+0.1-0.1 ~= 0.5) diff --git a/tests/scripts/save_file_command.lua b/tests/scripts/save_file_command.lua index cccaa2db2..2b5658bab 100644 --- a/tests/scripts/save_file_command.lua +++ b/tests/scripts/save_file_command.lua @@ -133,8 +133,8 @@ for _,cm in ipairs{ ColorMode.RGB, app.sprite = spr app.command.SaveFileCopyAs{ filename=fn, slice="small_slice", scale=scale } local c = app.open(fn) - assert(c.width == slice.bounds.width*scale) - assert(c.height == slice.bounds.height*scale) + assert(c.width == math.floor(slice.bounds.width*scale)) + assert(c.height == math.floor(slice.bounds.height*scale)) local testImg = Image(spr.cels[1].image, spr.slices[1].bounds) fix_images(testImg, scale, fileExt, c, cm, c1) diff --git a/tests/scripts/sprite.lua b/tests/scripts/sprite.lua index 3bb536219..ac964eada 100644 --- a/tests/scripts/sprite.lua +++ b/tests/scripts/sprite.lua @@ -21,8 +21,8 @@ do a:resize(6, 8) assert(a.width == 6) assert(a.height == 8) - assert(a.cels[1].image.width == 32 * 6 / 4) -- Check that the image was resized (not only the canvas) - assert(a.cels[1].image.height == 64 * 8 / 5) + assert(a.cels[1].image.width == math.floor(32 * 6 / 4)) -- Check that the image was resized (not only the canvas) + assert(a.cels[1].image.height == math.floor(64 * 8 / 5)) a:crop{x=-1, y=-1, width=20, height=30} assert(a.width == 20) assert(a.height == 30) diff --git a/third_party/lua b/third_party/lua index 04abf20c9..2a00e6b00 160000 --- a/third_party/lua +++ b/third_party/lua @@ -1 +1 @@ -Subproject commit 04abf20c9e8c973c62b30d0b98f6884ff665b1ba +Subproject commit 2a00e6b0013f54ce80b6e3cefe6514e13229987a