pub fn module(lua: &Lua) -> Result<Table>Expand description
Register the flow module table with Lua.
Exposes:
flow.version(= string): crate versionflow.eval(node_table, ctx_table, dispatcher_fn, externs_table?) -> result_table: Lua-side entry to evaluate a flow.ir BluePrint with a Lua dispatcher fn. Optional 4th arg is a table of pure Lua functions resolved bycall_externExpr (canonicalopts.externsparity).
§Lua usage
local flow = require("flow") -- or set via lua.globals():set("flow", module(lua))
local node = {
kind = "step",
ref = "uppercase",
["in"] = { op = "path", at = "$.input" },
out = { op = "path", at = "$.output" },
}
local function dispatcher(ref, input)
if ref == "uppercase" then
return string.upper(input)
end
end
local result = flow.eval(node, { input = "hello" }, dispatcher)
assert(result.output == "HELLO")
-- call_extern: whitelist pure Lua fns via the externs table
local node2 = {
kind = "assign",
at = { op = "path", at = "$.root" },
value = { op = "call_extern", ref = "math.sqrt",
args = { { op = "path", at = "$.n" } } },
}
local result2 = flow.eval(node2, { n = 9 }, dispatcher,
{ ["math.sqrt"] = math.sqrt })
assert(result2.root == 3)