fix: Lua 5.1 compatibility in FFI#5
Merged
Merged
Conversation
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.
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.
This was referenced Jun 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: Lua 5.1 compatibility in FFI
PUC Lua 5.1 has no
math.maxinteger/math.mininteger(they are 5.3 additions, so both evaluate tonil), and it reads the 5.3 escapes"\u{...}"and"\xNN"by silently dropping the backslash:"\u{FFFF}"is the 7-byte stringu{FFFF}, with no parse error to warn anyone. Several FFI files relied on both.Consequences before this fix:
bottomChar/topCharwereu{0000}/u{FFFF}, sotoCharCode bottom == 117andtoEnum 0 :: Maybe CharreturnedNothing. Anything built onBoundedEnum Charwas broken.topInt/bottomIntwerenil;intDegreewould crash onmath.min(x, nil)the first timediv/moddegree logic ran.showCharImplcompared against"\x07"(reallyx07) and calledcode:toString(10), a method call on a number, which throws.showArrayImplreadxs[i - 1]out of 1-based array tables, so the first shown element was alwaysnil.Int bounds are now spelled out as the 32-bit literals (PureScript
Intis 32-bit), Char bounds are byte bounds ("\0"/"\255"— aCharis a single byte in pslua), the bell character uses the 5.1-supported"\a", and the show fixes are the obvious ones.Caught by the revived
purescript-lua-stringstest suite (purescript-lua/purescript-lua#36).