[SpaceLua] Use luaFormatNumber for number-to-string coercion in .. and table.concat
Replace raw `String(v)` calls with `luaFormatNumber` in the concatenation operator and `table.concat`, so that floats are formatted according to Lua semantics rather than JavaScript's. This fixes cases like `10.8*22..""` producing `237.60000000000002` instead of `237.6`, and ensures integer-valued floats carry the `.0` suffix as Lua requires. Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
luaCall,
|
||||
type LuaEnv,
|
||||
luaEquals,
|
||||
luaFormatNumber,
|
||||
luaGet,
|
||||
LuaMultiRes,
|
||||
LuaRuntimeError,
|
||||
@@ -77,10 +78,10 @@ export const tableApi = new LuaTable({
|
||||
return v;
|
||||
}
|
||||
if (typeof v === "number") {
|
||||
return String(v);
|
||||
return luaFormatNumber(v);
|
||||
}
|
||||
if (isTaggedFloat(v)) {
|
||||
return String(v.value);
|
||||
return luaFormatNumber(v.value, "float");
|
||||
}
|
||||
|
||||
const ty = typeof v === "object" && v instanceof LuaTable
|
||||
|
||||
Reference in New Issue
Block a user