fennel

package
v0.0.4-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT, MIT Imports: 6 Imported by: 0

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

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

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

func IsFennelFile(path string) bool

IsFennelFile reports whether path has the Fennel file extension. hex/lua uses this to auto-route .fnl files through Compile.

func Load

func Load(L *lua.LState) error

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

type Session struct {
	L *lua.LState
}

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

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

NewSession returns a Session bound to L. Calls Load if needed.

func (*Session) Close

func (s *Session) Close() error

Close releases any session-scoped resources. No-op in v1 since Fennel doesn't allocate a persistent env like Teal does.

func (*Session) Compile

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

Compile transpiles source through the session. Currently equivalent to the package-level Compile; kept as a method for forward compatibility (macro state, persistent scope) and API symmetry with hex/lua/teal.

Jump to

Keyboard shortcuts

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