A CLI process that calls two registered functions (double and greet) via funcs.call(). Demonstrates how processes
invoke stateless functions by registry name.
Terminal Host (app:terminal)
└── Process (app:cli)
├── funcs.call("app:double", 21) → 42
├── funcs.call("app:greet", "Alice") → "Hello, Alice! ..."
├── funcs.call("app:double", 1..5) → loop
└── return 0
Registry:
app:double (function.lua) → n * 2
app:greet (function.lua) → "Hello, " .. name
A process.lua uses the funcs module to call function.lua entries by their registry ID. Functions are stateless —
call, get result, done.
02-func-call/
├── wippy.lock
└── src/
├── _index.yaml # Registry: terminal host, process host, functions, CLI process
├── cli.lua # main() → calls double and greet via funcs.call()
├── double.lua # call(n) → n * 2
└── greet.lua # call(name) → greeting string
| Entry | Kind | Purpose |
|---|---|---|
app:terminal |
terminal.host |
Terminal host (provides stdout) |
app:processes |
process.host |
Process host (runs function invocations) |
app:double |
function.lua |
Doubles a number |
app:greet |
function.lua |
Greets a person by name |
app:cli |
process.lua |
CLI entry point that calls both functions |
cd examples/02-func-call
wippy init
wippy run -x app:cliOutput:
=== Function Calls ===
double(21) = 42
greet('Alice') = Hello, Alice! Welcome to Wippy.
Calling double() in a loop:
double(1) = 2
double(2) = 4
double(3) = 6
double(4) = 8
double(5) = 10
Functions are stateless. Each call is independent.
function.lua— a stateless callable entry. Defines acall()method that takes arguments and returns a result. No persistent state between invocations.funcs.call(id, ...args)— invokes a registered function by its entry ID (e.g.,"app:double"). Returnsresult, err— always check for errors.- Process vs Function — a
process.luahas amain()that runs continuously with its own memory. Afunction.luahas acall()that runs once per invocation. Processes call functions, not the other way around. process.host— required for running function invocations. The process host manages the worker pool that executesfuncs.call()requests.