Skip to content

fix: use bound argument n in Format.lua FFI instead of unbound number#2

Merged
Unisay merged 2 commits into
masterfrom
fix/numbers-format
Jun 14, 2026
Merged

fix: use bound argument n in Format.lua FFI instead of unbound number#2
Unisay merged 2 commits into
masterfrom
fix/numbers-format

Conversation

@Unisay

@Unisay Unisay commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

Closes #1

The Lua FFI in src/Data/Number/Format.lua passed an unbound variable number to string.format, while the actual Number argument is bound as n (the functions are curried Int -> Number -> String, so d is the digit count and n is the number). At runtime number resolved to a nil global, so toPrecisionNative, toFixedNative, and toExponentialNative all errored instead of formatting their input.

This replaces number with the real argument n in all three calls. Minimal change, src only.

Verified: nix develop -c ./scripts/build exits 0; luacheck --quiet --std min src/Data/Number/Format.lua is clean (the 6 accessing undefined variable number / unused argument n warnings are gone). A direct Lua smoke test now formats numbers correctly (e.g. toPrecisionNative(6)(1234.56789) -> 1234.567890).

Note: toFixedNative still uses the %d (integer) specifier rather than %f, which truncates floats and diverges from JS toFixed. That is a separate correctness defect tracked in the issue and intentionally left out of this minimal fix.

The native formatting functions in src/Data/Number/Format.lua passed an
unbound variable `number` to string.format while the actual Number argument
was bound as `n`. At runtime `number` resolved to a nil global, so
toPrecisionNative/toFixedNative/toExponentialNative errored instead of
formatting their input. Reference each function's real argument `n`.

Closes #1
@Unisay Unisay force-pushed the fix/numbers-format branch from b0ce238 to 61f141b Compare June 14, 2026 11:23
@Unisay Unisay merged commit 8226836 into master Jun 14, 2026
@Unisay Unisay deleted the fix/numbers-format branch June 14, 2026 11:25
@Unisay Unisay self-assigned this Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Format.lua FFI references unbound variable number instead of its n argument

1 participant