Repository navigation
A hardening release. Scripts can no longer crash, hang or exhaust the memory of the interpreter through the compiler, the VM, the core library or the native modules: each of those paths now raises an ordinary error that pcall can catch. luascript fmt no longer changes what a program means, and luascript pkg install refuses a dependency that does not match its locked commit. The bytecode format is unchanged (SerialVersion 3), so binaries made with luascript build on 3.0.0 still run.
Install
go install github.com/hilthontt/luascript/v3/cmd/luascript@latestOr download a prebuilt binary below: Linux and macOS (amd64, arm64) as .tar.gz, Windows (amd64) as .zip. Each archive has a .sha256 file next to it; check it with sha256sum -c luascript-<os>-<arch>.sha256. The binaries are built by GitHub Actions from this tag, with CGO_ENABLED=0, so the ui module is the headless stub and plugin reports supported = false. The Windows binary is not code-signed, so SmartScreen may warn the first time you run it.
Behavior changes
These follow Lua 5.4. Scripts that relied on the old, looser behavior may now raise an error.
string.formataccepts at most two digits for width and precision, so"%999d"raisesinvalid conversioninstead of building a huge string.- Integer arguments given a float with a fractional part raise
number has no integer representationinstead of being truncated. - A pattern match that recurses too deeply raises
pattern too complexinstead of silently reporting no match. The old behavior made patterns such as("a?"):rep(n) .. ("a"):rep(n)backtrack for an exponential time. table.remove(t, pos)checksposthe way Lua 5.4 does. On an empty table it accepts0and#t + 1.- More than 200 coroutines resumed inside each other raises
C stack overflow. - A coroutine that yields while its
__closehandlers run after it died raisesattempt to yield across a C-call boundary. It used to hang. - Size limits on native modules:
crypto.password_hashcapstime,memory(1 GiB),key_lengthandsalt_length, andcrypto.password_verifytreats a stored hash with larger values as malformed.queue.channelcapacity is at most 16 777 216.plot.histogramandstats.histogrambins are at most 1 048 576.ndarray.arangerejects ranges that are too long and steps too small to advance.
Added
pairshonors the__pairsmetamethod.__callhandlers can themselves be callable tables. The chain is followed as in Lua 5.4, and a loop raises an error instead of overflowing the stack.
Fixed
Compiler
- A NUL byte in the source no longer ends the script early. The rest of the file used to be dropped silently.
- Very deep expressions (long
a.b.c…,f()()…,a + b + …chains and large interpolated strings) produce a syntax error instead of crashing the process with a stack overflow. - Long
and/or, index, call and method chains compile in linear time. An 80 000-term chain used to take minutes. - Recursive generic types such as
type L<T> = { n: L<L<T>> }no longer make the type checker run for an exponential time, and deeply nested conditions no longer slow down type narrowing.
Runtime
- An uncaught error whose
__tostringitself fails no longer crashes the process. It prints(error object is a … value). string.formatprintsinf,-infandnanthe way C and Lua do, not as+InfandNaN.math.modfreturns an integer argument unchanged with fraction0.0, and returns fraction0.0for infinity.string.byterefuses ranges of more than 16M bytes instead of allocating without bound.table.moveraisesdestination wrap aroundinstead of overflowing.
Native modules
- Loading an
mlmodel checks its layer sizes, activation, mode and loss, and that its weights match the layout. A corrupt or hostile model file used to crash the process or allocate unbounded memory. naivebayes:learnwith an unknown class raises an error instead of panicking.httpserver: a handler that returns a status outside 100–999 gets a500response explaining the bug, instead of a dropped connection.io.linesandfile:lineson a handle that is closed or not readable raise an error instead of panicking.timefunctions called with a missing timestamp argument raise an error instead of panicking.stats.quantileandstats.percentilerejectNaN.
Formatter
luascript fmtadds parentheses where the parser's desugaring needs them. For example,x *= a + bis printed asx = x * (a + b), notx = x * a + b, and`a{b}`:upper()keeps its parentheses.- -xkeeps its space instead of becoming a--comment.- Strings are quoted with LuaScript escapes. Go's
\uXXXXform, which the lexer does not read, used to change the string's contents. - A
returnwith no value is no longer joined to the nextmatcharm. - Long call and index chains format in linear time.
Security
luascript pkg installchecks out a locked dependency by its exact commit and refuses the install if the fetched commit differs from the lock file. A branch or tag named after the pinned SHA could previously replace it.- The bytecode cache directory is created with mode
0700instead of0755, so other users cannot read it. - Fixed the warnings reported by CodeQL code scanning.
Dependencies
- Go:
modernc.org/sqlite1.62.0,github.com/mattn/go-sqlite31.14.53,golang.org/x/crypto0.59.0,github.com/go-sql-driver/mysql1.10.2,github.com/microsoft/go-mssqldb1.12.0,fyne.io/fyne/v22.8.2. - Website: Next.js 16.4.6, React 19.3.1, Tailwind CSS 4.3.5, Shiki 4.6.0 and smaller updates.
- CI:
softprops/action-gh-release3.0.4,actions/upload-artifact7.0.2,actions/download-artifact8.0.2.
Full changelog: v3.0.0...v3.1.0