Title: [fork-ffi] enums: fromCharCode — fromCharCode is bound directly to string.char, which builds a string… · Issue #80 · purescript-lua/purescript-lua · GitHub
Open Graph Title: [fork-ffi] enums: fromCharCode — fromCharCode is bound directly to string.char, which builds a string… · Issue #80 · purescript-lua/purescript-lua
X Title: [fork-ffi] enums: fromCharCode — fromCharCode is bound directly to string.char, which builds a string… · Issue #80 · purescript-lua/purescript-lua
Description: Package: purescript-lua-enums File: src/Data/Enum.lua Function: fromCharCode Class: semantics Severity: high fromCharCode is bound directly to string.char, which builds a string from raw byte values 0..255 and ERRORS for any value > 255 ...
Open Graph Description: Package: purescript-lua-enums File: src/Data/Enum.lua Function: fromCharCode Class: semantics Severity: high fromCharCode is bound directly to string.char, which builds a string from raw byte value...
X Description: Package: purescript-lua-enums File: src/Data/Enum.lua Function: fromCharCode Class: semantics Severity: high fromCharCode is bound directly to string.char, which builds a string from raw byte value...
Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/80
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[fork-ffi] enums: fromCharCode — fromCharCode is bound directly to string.char, which builds a string…","articleBody":"**Package:** purescript-lua-enums \n**File:** `src/Data/Enum.lua` \n**Function:** `fromCharCode` \n**Class:** semantics **Severity:** high\n\nfromCharCode is bound directly to string.char, which builds a string from raw byte values 0..255 and ERRORS for any value > 255 ('bad argument #1 to char (invalid value)', confirmed on Lua 5.1 for 256 and 65535). Even for 128..255 it emits a single raw byte (0x80-0xFF) which is invalid as a standalone UTF-8 character, not the Latin-1 code point JS produces. The JS FFI is `String.fromCharCode(c)`, valid over the entire Char range 0..65535. fromCharCode backs charToEnum, which Data.Enum uses for the Char instances of toEnum/succ/pred; so any Char above U+007F is wrong and any Char above U+00FF throws at runtime. Correct only for the ASCII subrange 0..127.\n\n**Current (Lua):**\n```lua\nfromCharCode = (string.char)\n```\n\n**Expected:** JS: String.fromCharCode(c) yields the character for code unit c over 0..65535 (e.g. 65 -> 'A', 233 -> 'é', 256 -> U+0100 'Ā', 65535 -> U+FFFF), as a valid UTF-8 string after compilation.\n\n**Proposed fix:**\n```lua\nEncode the code point as UTF-8 (full BMP range) instead of a single byte. E.g.:\n fromCharCode = function(n)\n if n \u003c 0x80 then return string.char(n) end\n if n \u003c 0x800 then return string.char(0xC0 + math.floor(n / 0x40), 0x80 + (n % 0x40)) end\n if n \u003c 0x10000 then return string.char(0xE0 + math.floor(n / 0x1000), 0x80 + (math.floor(n / 0x40) % 0x40), 0x80 + (n % 0x40)) end\n return string.char(0xF0 + math.floor(n / 0x40000), 0x80 + (math.floor(n / 0x1000) % 0x40), 0x80 + (math.floor(n / 0x40) % 0x40), 0x80 + (n % 0x40))\n end\nVerified on Lua 5.1: toCharCode(fromCharCode(233))==233, ...(65535)==65535, ...(0x100)==256, no errors.\n```\n\n_Found by the FFI audit; reproduced under Lua 5.1._","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-06-15T11:23:59Z","url":"https://github.com/purescript-lua/purescript-lua/issues/80"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:abbf2fa1-28c9-b7cd-f66e-30515a8bf16a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 95F0:38C5CF:9C5776:CB1A82:6B00DFA8 |
| html-safe-nonce | 384a8798706f60ff4103bf29fb5e6ab78f4fca9ba09fb2ce0d18493b836d0597 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NUYwOjM4QzVDRjo5QzU3NzY6Q0IxQTgyOjZCMDBERkE4IiwidmlzaXRvcl9pZCI6IjU3NDYyODI4NTc4ODI1MDkyMjQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b5170b6ceef1607eefe9680411a3b12e01fe4ad9eb8354e1f7ab7e6048e59e67 |
| hovercard-subject-tag | issue:4664607234 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/purescript-lua/purescript-lua/80/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1efc134c716678401adf781ce855896ee1140519fed494ce76d7bf4a605c1739/purescript-lua/purescript-lua/issues/80 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1efc134c716678401adf781ce855896ee1140519fed494ce76d7bf4a605c1739/purescript-lua/purescript-lua/issues/80 |
| og:image:alt | Package: purescript-lua-enums File: src/Data/Enum.lua Function: fromCharCode Class: semantics Severity: high fromCharCode is bound directly to string.char, which builds a string from raw byte value... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Unisay |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| turbo-cache-control | no-preview |
| go-import | github.com/purescript-lua/purescript-lua git https://github.com/purescript-lua/purescript-lua.git |
| octolytics-dimension-user_id | 131581790 |
| octolytics-dimension-user_login | purescript-lua |
| octolytics-dimension-repository_id | 587200487 |
| octolytics-dimension-repository_nwo | purescript-lua/purescript-lua |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 587200487 |
| octolytics-dimension-repository_network_root_nwo | purescript-lua/purescript-lua |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width