From c63dec6c2920e4522c11757547fa6e54c5a43c8d Mon Sep 17 00:00:00 2001 From: Yura Lazarev Date: Sun, 14 Jun 2026 10:33:03 +0200 Subject: [PATCH 1/2] fix: use bound argument n in Format.lua FFI instead of unbound number 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 Unisay/purescript-lua-numbers#1 --- src/Data/Number/Format.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Data/Number/Format.lua b/src/Data/Number/Format.lua index c109e45..137653d 100644 --- a/src/Data/Number/Format.lua +++ b/src/Data/Number/Format.lua @@ -1,6 +1,6 @@ return { - toPrecisionNative = (function(d) return function(n) return string.format("%." .. tostring(d) .. "f", number) end end), - toFixedNative = (function(d) return function(n) return string.format("%." .. tostring(d) .. "d", number) end end), - toExponentialNative = (function(d) return function(n) return string.format("%." .. tostring(d) .. "e", number) end end), + toPrecisionNative = (function(d) return function(n) return string.format("%." .. tostring(d) .. "f", n) end end), + toFixedNative = (function(d) return function(n) return string.format("%." .. tostring(d) .. "d", n) end end), + toExponentialNative = (function(d) return function(n) return string.format("%." .. tostring(d) .. "e", n) end end), toString = (function(num) return tostring(num) end) } From 61f141b37fa2e3412d97cd70f22596cac8b0e126 Mon Sep 17 00:00:00 2001 From: Yura Lazarev Date: Sun, 14 Jun 2026 13:05:44 +0200 Subject: [PATCH 2/2] test: regression guard for Format.lua using the bound argument n --- scripts/test | 6 ++++++ test/regression/format.lua | 8 ++++++++ 2 files changed, 14 insertions(+) create mode 100755 scripts/test create mode 100644 test/regression/format.lua diff --git a/scripts/test b/scripts/test new file mode 100755 index 0000000..03cfc1a --- /dev/null +++ b/scripts/test @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -euo pipefail + +echo "Running regression tests..." + +lua test/regression/format.lua diff --git a/test/regression/format.lua b/test/regression/format.lua new file mode 100644 index 0000000..0fb2d6d --- /dev/null +++ b/test/regression/format.lua @@ -0,0 +1,8 @@ +-- Regression guard: Format.lua must use its bound argument n, not an +-- unbound `number` global (nil at runtime, which made every formatter error). +local M = assert(dofile("src/Data/Number/Format.lua")) + +assert(type(M.toPrecisionNative(6)(1234.56789)) == "string", + "toPrecisionNative must format its bound argument, not error on a nil global") + +print("OK Format.lua uses the bound argument n")