Skip to content

fix: Lua 5.1 compatibility in FFI#5

Merged
Unisay merged 2 commits into
masterfrom
fix/lua51-compat
Jun 13, 2026
Merged

fix: Lua 5.1 compatibility in FFI#5
Unisay merged 2 commits into
masterfrom
fix/lua51-compat

Conversation

@Unisay

@Unisay Unisay commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator

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 to nil), and it reads the 5.3 escapes "\u{...}" and "\xNN" by silently dropping the backslash: "\u{FFFF}" is the 7-byte string u{FFFF}, with no parse error to warn anyone. Several FFI files relied on both.

Consequences before this fix:

  • bottomChar/topChar were u{0000}/u{FFFF}, so toCharCode bottom == 117 and toEnum 0 :: Maybe Char returned Nothing. Anything built on BoundedEnum Char was broken.
  • topInt/bottomInt were nil; intDegree would crash on math.min(x, nil) the first time div/mod degree logic ran.
  • showCharImpl compared against "\x07" (really x07) and called code:toString(10), a method call on a number, which throws.
  • showArrayImpl read xs[i - 1] out of 1-based array tables, so the first shown element was always nil.

Int bounds are now spelled out as the 32-bit literals (PureScript Int is 32-bit), Char bounds are byte bounds ("\0"/"\255" — a Char is 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-strings test suite (purescript-lua/purescript-lua#36).

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.

This comment was marked as resolved.

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.
@Unisay Unisay merged commit e071698 into master Jun 13, 2026
1 check passed
@Unisay Unisay deleted the fix/lua51-compat branch June 13, 2026 07:40
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.

2 participants