Skip to content
HilthonTTPublic

About

A Lua-flavored language with a stack-based virtual machine and Luau-style gradual types, written in Go.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

LuaScript logo

LuaScript

Lua 5.4 with Luau-style gradual types, compiled to bytecode for a stack VM written in Go.
Documentation · Quick start · Examples · Releases

CI Website CodeQL License: MIT

Writing a typed LuaScript program and running it

The syntax tracks Lua 5.4: the same chunks, scoping rules, metatables, coroutines and standard-library shape. Optional type annotations are checked at compile time and erased before bytecode, so untyped Lua runs unchanged and typed code costs nothing at run time.

Install

go install github.com/hilthontt/luascript/v3/cmd/luascript@latest

Or download a prebuilt binary for Linux, macOS or Windows from Releases, or build from source with go build -o luascript ./cmd/luascript. See Installation.

A taste

--!strict
type Planet = { name: string, moons: number, rings: string? }

enum Shape
    Circle(number),
    Rect(number, number),
end

local function area(s: Shape): number
    match s do
        Shape.Circle(r)  -> return math.pi * r * r
        Shape.Rect(w, h) -> return w * h
    end
    return 0
end

local p: Planet = { name = "Mars", moons = 2 }
print(`{p.name} has {p.moons} moons`)    -- Mars has 2 moons
print(area(Shape.Rect(3, 4)))             -- 12
print(p.rings ?? "no rings")              -- no rings
luascript planets.lsc     # run a script
luascript                 # start the REPL

What you get

  • Lua 5.4 at heart: metatables, coroutines, closures, goto, integer subtypes, <const>/<close> and the full pattern library.
  • Gradual types: unions, optionals, literal types, generics with constraints, interfaces, intersections and narrowing. The standard library is typed, so math.sqrt(true) is a compile error.
  • Structs, tagged enums and match, with exhaustiveness checking.
  • Modern syntax: ?., ??, |>, destructuring, spread, continue, if-expressions, default parameters and string interpolation.
  • Real error handling: try/catch/throw, defer, and stack tracebacks across modules.
  • Batteries included: json, an HTTP client and server, crypto, SQL databases, regexp, time, compression, collections, job queues and channels.
  • Data science: N-d arrays, dataframes, stats, linear algebra, clustering, neural nets and SVG plots.
  • Tooling: a formatter, a language server with a VS Code extension, a test runner, a static analyzer, a profiler, offline docs (luascript doc), and luascript build to bundle a script into a single executable.

All of it is covered in the documentation. For internals, see DESIGN.md and the architecture guide.

Contributing

See CONTRIBUTING.md. Before sending a change, run make check (gofmt, vet and the full test suite). Participation is governed by the Code of Conduct; report security problems through SECURITY.md, not a public issue.

Inspired by Lua 5.4 (syntax and semantics), Luau (the type system) and Goby (the original stack VM scaffolding).

License

MIT. See LICENSE.

About

A Lua-flavored language with a stack-based virtual machine and Luau-style gradual types, written in Go.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages