provider

package
v0.0.5-alpha Latest Latest
Warning

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

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

Documentation

Overview

Package provider is the default hex/lua service provider.

It constructs a shared *lua.Environment during Register and binds it into the container under "lua" so other providers can resolve it and contribute modules, globals, or preloaded scripts:

// In another provider's Register:
env, _ := container.Make[*hexlua.Environment](app, "lua")
env.PreloadModule("myapp", myModule.Loader)
env.SetGlobal("build_version", "v1.2.3")

As a foundational convenience, this provider also installs the 'config' and 'log' Lua modules automatically — both are always-available in a hex app, so binding them here avoids forcing every scaffold to wire dedicated bridge providers for them. Other services (db, cache, queue, events, ai, ...) are optional; their own providers install their Lua modules when they see a shared env in the container.

Register order: hex/config/provider first (its "config" binding is resolved here), then hex/log/provider, then this provider.

Shutdown closes the environment.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Configs

func Configs() fs.FS

Configs returns the embedded default TOML + CUE files this provider contributes to hex/config. Add it to hex/config.Provider.Sources to pick up the "repl" namespace (mode = "teal" | "lua").

func ReplCommand

func ReplCommand(app *hex.App) *cobra.Command

ReplCommand returns a cobra `repl` command that opens an interactive Teal/Lua REPL against the app's shared *hex/lua.Environment.

The REPL sees every Lua module registered by framework providers (agent, and — as Phase 3 lands — db, config, cache, log, events, queue, env) and by consumer providers (domain services). This is the Tinker / Rails console / Phoenix IEx analogue for hex apps: shell into a pod, inspect the live DB, prototype a script.

Consumer apps mount it under their root command; the scaffolder wires it automatically. Wire it manually with:

rootCmd.AddCommand(luaprovider.ReplCommand(app))

Mode selection precedence (highest to lowest):

  1. --mode flag on the command
  2. repl.mode in the app config
  3. Teal (framework default)

A prod banner is added when app.Environment() reports Production.

func RunCommand

func RunCommand(app *hex.App) *cobra.Command

RunCommand returns a cobra `run` command that executes a Lua, Teal, or Fennel script against the app's shared *hex/lua.Environment.

This is the container-aware sibling of the top-level `hex run` command: same flags, same source-resolution rules — but the script sees every Lua module registered by framework providers (config, log, env, events, db, cache, queue, ai, …) and by consumer providers (domain services). It is the "throwaway one-liner against the live app" tool — Tinker's `--execute`, Rails's `runner`, Phoenix's `mix run -e`.

Consumer apps mount it under their root command; the scaffolder wires it automatically. Wire it manually with:

rootCmd.AddCommand(luaprovider.RunCommand(app))

Source resolution (same as `hex run`):

app run script.lua                  # file (extension picks language)
app run script.tl
app run script.fnl
app run -                           # stdin (--lang selects; default lua)
app run -c 'print(db.query(...))'   # inline
app run -c '(print (env.get "PORT"))' --lang fnl

Use --check to validate without executing.

Types

type Provider

type Provider struct {
	provider.Base

	// Binding is the container key for the environment. Defaults to
	// "lua".
	Binding string

	// Options are passed verbatim to hexlua.New.
	Options []hexlua.Option
	// contains filtered or unexported fields
}

Provider wires a shared *hex/lua.Environment into the container. Other providers register modules/globals against it in their own Register phase.

func (*Provider) Register

func (p *Provider) Register(app provider.Application) error

Register builds the environment, binds it into the container, and preloads the foundational `config` and `log` Lua modules.

func (*Provider) Shutdown

func (p *Provider) Shutdown(_ context.Context, _ provider.Application) error

Shutdown closes the shared Lua environment.

Jump to

Keyboard shortcuts

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