Builtin Library
README.md
procgen.collapse
Lifts a section of a graph's code into a node of its own. A graph is the code
of its init.luau (proc.define(function(g) ... end)), and a section is a run
of whole statements of that function, named by the lines it spans
(from, to): typically a few node calls that together do one job.
- The node's inputs are the locals declared before the section that its
code reads. A graph input it reads is declared in the node as the graph
declares it (
local seed = g:input("seed", 3)); any other value becomes an input typed by what the section wires it into. - The node's outputs are the locals the section declares that the code after it reads.
- A local function the section calls goes into the node with it: moved when nothing left in the graph calls it, copied when something does.
- The section is replaced by one call of the node, so the graph builds from
the same calls and cooks to the same result:
local strewn = g["~/fx/Strew"]({ seed = seed, spots = spots }). A node giving several outputs is called once and its outputs are read off the table it returns.
The node lands beside the graph (or in into) as <name>.procNode, with the
description as its g:describe, .metadata and README, and is found by
procgen.searchNodes and described by procgen.describeNode at once. The
graph's new source is written only once it builds.
A section holding the graph's own inputs or outputs (g:input, g:output,
return { ... }), or assigning to a value declared before it, is refused with
the line and why.
procgen.flatten is the inverse: it writes a node's body back out in place of
its call. procgen.reference puts an existing node in place of a section.
Part of procgen.toolbox, called as tools.use("procgen", "collapse", ...) (zero procgen collapse in the engine shell). Returns
{ node, call, inputs, outputs, copied, moved, lines, source, nodeSource, diagnostics }.