From bf511cb48eeaf6d24e99d3a153c215d1e1125566 Mon Sep 17 00:00:00 2001 From: Yura Lazarev Date: Fri, 12 Jun 2026 21:38:30 +0200 Subject: [PATCH 1/2] fix: Lua 5.1 compatibility in FFI PUC Lua 5.1 has no math.maxinteger/math.mininteger (nil at runtime) and silently mangles the 5.3+ escapes "\u{...}" and "\xNN" (the backslash is dropped, so "\u{FFFF}" reads as the 7-byte string "u{FFFF}"). This broke Bounded Char/Int and Show Char in ways the parser never reports. Also fix showCharImpl calling a method on a number (code:toString) and showArrayImpl reading 0-based indices from 1-based array tables. --- src/Data/Bounded.lua | 14 ++++++++++---- src/Data/EuclideanRing.lua | 3 ++- src/Data/Show.lua | 6 +++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Data/Bounded.lua b/src/Data/Bounded.lua index 296d6fc8..e723c5a2 100644 --- a/src/Data/Bounded.lua +++ b/src/Data/Bounded.lua @@ -1,8 +1,14 @@ +-- Lua 5.1 compatibility: +-- * math.maxinteger/math.mininteger appeared in Lua 5.3; PureScript Int +-- is a 32-bit integer, so its bounds are spelled out literally. +-- * "\u{...}" escapes appeared in Lua 5.3 (PUC Lua 5.1 silently reads +-- "\u" as "u"). A Char is a single byte in pslua, so its bounds are +-- the byte bounds. return { - topInt = (math.maxinteger), - bottomInt = (math.mininteger), - topChar = ("\u{FFFF}"), - bottomChar = ("\u{0000}"), + topInt = (2147483647), + bottomInt = (-2147483648), + topChar = ("\255"), + bottomChar = ("\0"), topNumber = (1 / 0), bottomNumber = (-1 / 0) } diff --git a/src/Data/EuclideanRing.lua b/src/Data/EuclideanRing.lua index a600582c..e419766f 100644 --- a/src/Data/EuclideanRing.lua +++ b/src/Data/EuclideanRing.lua @@ -1,5 +1,6 @@ return { - intDegree = (function(x) return math.min(math.abs(x), math.maxinteger) end), + -- math.maxinteger is Lua 5.3+; PureScript Int is 32-bit + intDegree = (function(x) return math.min(math.abs(x), 2147483647) end), intDiv = (function(x) return function(y) if y == 0 then return 0 end diff --git a/src/Data/Show.lua b/src/Data/Show.lua index 33112071..bf3446ec 100644 --- a/src/Data/Show.lua +++ b/src/Data/Show.lua @@ -4,14 +4,14 @@ return { showCharImpl = (function(n) local code = n:byte() if code < 0x20 or code == 0x7F then - if n == "\x07" then return "'\\a'" end + if n == "\a" then return "'\\a'" end if n == "\b" then return "'\\b'" end if n == "\f" then return "'\\f'" end if n == "\n" then return "'\\n'" end if n == "\r" then return "'\\r'" end if n == "\t" then return "'\\t'" end if n == "\v" then return "'\\v'" end - return "'\\" .. code:toString(10) .. "'" + return "'\\" .. tostring(code) .. "'" end if n == "'" or n == "\\" then return "'\\" .. n .. "'" end return "'" .. n .. "'" @@ -21,7 +21,7 @@ return { return function(xs) local l = #xs local ss = {} - for i = 1, l do ss[i] = f(xs[i - 1]) end + for i = 1, l do ss[i] = f(xs[i]) end return "[" .. table.concat(ss, ",") .. "]" end end) From bb19309b4900af4e01f6552c14ec824c16b9261b Mon Sep 17 00:00:00 2001 From: Yura Lazarev Date: Sat, 13 Jun 2026 09:28:39 +0200 Subject: [PATCH 2/2] ci: build with nix instead of the inherited bower workflow The workflow was the upstream PureScript bower-based CI, carried over when the repo was forked. This fork has no bower.json and builds with nix + spago, so CI failed at "bower install" on every run. Replace it with one that enters the dev shell and runs scripts/build plus luacheck, using the IOG and purescript-lua binary caches so pslua is fetched rather than built. --- .github/workflows/ci.yml | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 07fb36b9..b7c2ace4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,26 +9,17 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: purescript-contrib/setup-purescript@main + - uses: cachix/install-nix-action@v27 with: - purescript: "unstable" + extra_nix_config: | + accept-flake-config = true + extra-substituters = https://cache.iog.io https://purescript-lua.cachix.org + extra-trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= purescript-lua.cachix.org-1:yLs4ei2HtnuPtzLekOrW3xdfm95+Etw15gwgyIGTayA= - - uses: actions/setup-node@v2 - with: - node-version: "14.x" - - - name: Install dependencies - run: | - npm install -g bower - npm install - bower install --production - - - name: Build source - run: npm run-script build + - name: Build + run: nix develop -c ./scripts/build - - name: Run tests - run: | - bower install - npm run-script test --if-present + - name: Luacheck + run: nix develop -c luacheck --quiet --std min src/