teal

package
v0.0.3-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package teal makes .tl (Teal) source files runnable through gopher-lua by embedding the Teal compiler + Lua 5.2 compatibility shims. Consumers do not import this package directly; hex/lua's Environment lazy-loads it when it encounters a .tl file.

Runtime model

Teal's compiler is itself Lua (tl.lua). We load it into the same gopher-lua state that will execute compiled Teal output. Compilation happens by calling tl.process(filename) + tl.pretty_print_ast(ast, "5.1") from Go through the state, producing plain Lua source that gopher-lua then compiles + executes as normal.

See NOTICE.md for attribution + the patch trail on the vendored Lua files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(L *lua.LState, source, filename string) error

Check runs tl.process on the source but stops before code generation, returning any syntax + type errors found. Useful for CI: fail the build on Teal type errors without executing anything.

func Compile

func Compile(L *lua.LState, source, filename string) (string, error)

Compile transpiles a Teal source string into Lua source. filename is used only for error reporting.

L must have had Load called on it beforehand.

func Load

func Load(L *lua.LState) error

Load installs the Teal compiler into L. Subsequent calls to Compile / Check / Exec against the same state reuse the loaded compiler. Safe to call more than once — the bootstrap script is idempotent (re-assigning tl and clearing tl.cache).

Types

type Session

type Session struct {
	L *lua.LState
	// contains filtered or unexported fields
}

Session wraps an LState with a persistent Teal env, so subsequent compiles see prior declarations. Use this for REPLs and any other interactive loop where each snippet is its own "chunk" but must share a symbol table with previous chunks.

Non-Session Compile/Check calls typecheck each snippet in isolation (correct for scripts, wrong for REPLs).

func NewLaxSession

func NewLaxSession(L *lua.LState) (*Session, error)

NewLaxSession is like NewSession but flips Teal's lax typecheck mode on. In lax mode Teal permits implicit globals (foo = 12 without an explicit declaration) and generally relaxes strictness — well-suited to REPL interaction where every line is its own chunk and users don't want to sprinkle 'global' declarations.

func NewSession

func NewSession(L *lua.LState) (*Session, error)

NewSession initialises a Teal env stashed on L under a private global (_hex_teal_env) with strict typechecking. L must have had Load called on it.

Use NewLaxSession for REPL-friendly loose typechecking that permits implicit globals and Lua-esque patterns.

func (*Session) AddTypeStub

func (s *Session) AddTypeStub(moduleName, source string) error

AddTypeStub writes a Teal .d.tl file for moduleName into the session's private types directory (created on first call) and prepends the directory to package.path so Teal's require() resolution finds it.

Callers typically pass the source verbatim from *hex/lua.Environment.Types() — hex/lua/repl.Run does this automatically for Teal sessions.

func (*Session) Close

func (s *Session) Close() error

Close removes the session's private types directory. Safe to call multiple times.

func (*Session) Compile

func (s *Session) Compile(source, filename string) (string, error)

Compile transpiles Teal source using the session's persistent env, so declarations from prior Compile calls remain visible.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL