Documentation
¶
Overview ¶
Package fennel makes .fnl (Fennel) source files runnable through gopher-lua by embedding the Fennel compiler (a self-contained Lua source file distributed by the Fennel project). Consumers do not import this package directly; hex/lua's Environment lazy-loads it when it encounters a .fnl file.
Runtime model ¶
The Fennel compiler is itself Lua (fennel.lua, the amalgamation build from https://fennel-lang.org). We load it into the same gopher-lua state that will execute compiled Fennel output. Compilation happens by calling fennel.compileString(src, opts) from Go through the state, producing plain Lua source that gopher-lua then compiles + executes as normal.
This mirrors hex/lua/teal exactly \u2014 same shape, same API. The only differences are the language and the absence of a type-checker.
Framework module access ¶
Any Lua module registered via hex/lua.Environment.PreloadModule (db, cache, config, log, env, events, queue, agent, and any consumer-added modules) is transparently visible from Fennel source. Just require them like normal:
(local db (require :db))
(local rows (db.query "SELECT * FROM users WHERE active = ?" true))
(each [_ user (ipairs rows)]
(log.info "user" {:id user.id :name user.name}))
See NOTICE.md for attribution + license terms.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compile ¶
Compile transpiles Fennel source to Lua source. filename is used in error messages and (roughly) in source maps.
Non-session Compile compiles each snippet in isolation. Use a Session for REPL-style multi-chunk state where prior globals should remain visible.
func IsFennelFile ¶
IsFennelFile reports whether path has the Fennel file extension. hex/lua uses this to auto-route .fnl files through Compile.
func Load ¶
Load installs the Fennel compiler into L. Safe to call multiple times; subsequent calls are no-ops.
After Load, the LState exposes:
fennel the module table fennel.compileString(src, opts) Lua source, name-preserving fennel.eval(src, opts) compile + run fennel.dofile(path) compile + run a .fnl file
Consumers typically go through Compile/Session below.
Types ¶
type Session ¶
Session wraps an LState for interactive Fennel evaluation. Unlike Teal, Fennel doesn't have a persistent type environment to keep across compilations \u2014 it's dynamic \u2014 so Session is a thin marker that mostly exists for symmetry with teal.Session and to enable future features (macro persistence, scope tracking).
Callers should reuse a Session across REPL lines even though the runtime state (globals) automatically persists via the shared LState.
func NewSession ¶
NewSession returns a Session bound to L. Calls Load if needed.
func (*Session) Close ¶
Close releases any session-scoped resources. No-op in v1 since Fennel doesn't allocate a persistent env like Teal does.