Skip to content

LuaScript 3.1.0

Latest

Choose a tag to compare

@github-actions github-actions released this 26 Nov 23:33
· 8 commits to main since this release

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@latest

Or 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.format accepts at most two digits for width and precision, so "%999d" raises invalid conversion instead of building a huge string.
  • Integer arguments given a float with a fractional part raise number has no integer representation instead of being truncated.
  • A pattern match that recurses too deeply raises pattern too complex instead 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) checks pos the way Lua 5.4 does. On an empty table it accepts 0 and #t + 1.
  • More than 200 coroutines resumed inside each other raises C stack overflow.
  • A coroutine that yields while its __close handlers run after it died raises attempt to yield across a C-call boundary. It used to hang.
  • Size limits on native modules: crypto.password_hash caps time, memory (1 GiB), key_length and salt_length, and crypto.password_verify treats a stored hash with larger values as malformed. queue.channel capacity is at most 16 777 216. plot.histogram and stats.histogram bins are at most 1 048 576. ndarray.arange rejects ranges that are too long and steps too small to advance.

Added

  • pairs honors the __pairs metamethod.
  • __call handlers 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 __tostring itself fails no longer crashes the process. It prints (error object is a … value).
  • string.format prints inf, -inf and nan the way C and Lua do, not as +Inf and NaN.
  • math.modf returns an integer argument unchanged with fraction 0.0, and returns fraction 0.0 for infinity.
  • string.byte refuses ranges of more than 16M bytes instead of allocating without bound.
  • table.move raises destination wrap around instead of overflowing.

Native modules

  • Loading an ml model 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:learn with an unknown class raises an error instead of panicking.
  • httpserver: a handler that returns a status outside 100–999 gets a 500 response explaining the bug, instead of a dropped connection.
  • io.lines and file:lines on a handle that is closed or not readable raise an error instead of panicking.
  • time functions called with a missing timestamp argument raise an error instead of panicking.
  • stats.quantile and stats.percentile reject NaN.

Formatter

  • luascript fmt adds parentheses where the parser's desugaring needs them. For example, x *= a + b is printed as x = x * (a + b), not x = x * a + b, and `a{b}`:upper() keeps its parentheses.
  • - -x keeps its space instead of becoming a -- comment.
  • Strings are quoted with LuaScript escapes. Go's \uXXXX form, which the lexer does not read, used to change the string's contents.
  • A return with no value is no longer joined to the next match arm.
  • Long call and index chains format in linear time.

Security

  • luascript pkg install checks 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 0700 instead of 0755, so other users cannot read it.
  • Fixed the warnings reported by CodeQL code scanning.

Dependencies

  • Go: modernc.org/sqlite 1.62.0, github.com/mattn/go-sqlite3 1.14.53, golang.org/x/crypto 0.59.0, github.com/go-sql-driver/mysql 1.10.2, github.com/microsoft/go-mssqldb 1.12.0, fyne.io/fyne/v2 2.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-release 3.0.4, actions/upload-artifact 7.0.2, actions/download-artifact 8.0.2.

Full changelog: v3.0.0...v3.1.0