Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion std/lua/_lua/_hx_tostring.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,20 @@ function _hx_tostring(obj, depth)
elseif obj == _G.math.NEGATIVE_INFINITY then return "-Infinity"
elseif obj == 0 then return "0"
elseif obj ~= obj then return "NaN"
else return _G.tostring(obj)
else
-- Lua 5.3+ splits numbers into integer/float subtypes, so
-- tostring(1.0) == "1.0". Haxe prints whole-valued floats without
-- the trailing ".0" on every other target (js/python/neko/eval), so
-- strip it back off to keep Std.string consistent. Lua's float
-- formatter (%.14g) only ever appends an exact ".0" to
-- integer-looking output, so a suffix check is sufficient: scientific
-- notation ("1e+15"), fractions ("1.5") and NaN/Infinity are
-- untouched, and on Lua 5.1/LuaJIT (no ".0" suffix) this is a no-op.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is quite verbose, and it will be included in the user's output lua file so maybe it's best to shorten or remove it. (If we move more of this lua code to haxe like in #12600, we can have more freedom to add comments etc)

The comment also seems to not mention Lua 5.2.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I'll update it on the next go-round.

local s = _G.tostring(obj)
if _G.string.sub(s, -2) == ".0" then
return _G.string.sub(s, 1, -3)
end
return s
end
elseif tstr == "boolean" then return _G.tostring(obj)
elseif tstr == "userdata" then
Expand Down
6 changes: 0 additions & 6 deletions tests/unit/src/unit/TestBasetypes.hx
Original file line number Diff line number Diff line change
Expand Up @@ -494,19 +494,13 @@ class TestBasetypes extends Test {
var v1:unit.MyAbstract.MyVector = new unit.MyAbstract.MyPoint3(1, 1, 1);
var v2:unit.MyAbstract.MyVector = new unit.MyAbstract.MyPoint3(1, 2, 3);
eq("(2,3,4)", v1 + v2);
#if !lua
eq("(2,4,6)", v2 * 2.);
#end
var v1Old = v1;
v1 *= 2.;
#if !lua
eq("(2,2,2)", v1);
#end
eq(v1Old, v1);
var v3 = v1 * 2.;
#if !lua
eq("(4,4,4)", v3);
#end
f(v1 == v3);

var i:unit.MyAbstract.MyInt = 1;
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/src/unit/issues/Issue3345.hx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ private abstract Meters(Float) from Float {
}

class Issue3345 extends Test {
#if !lua
function test() {
var acc:Meters = .0;
for (i in 0...10)
Expand All @@ -36,5 +35,4 @@ class Issue3345 extends Test {
acc -= 10;
eq("-100(m)", acc);
}
#end
}
Loading