module
Capy
module
module is the type of a handle returned by unit_load(). It represents a loaded unit whose exported functions you can call.
function RENDER()
{
var target := unit_load("/doc/examples/call_target.capy")
print(target.default_input(), "\n")
}Output
defaultIt is opaque
There is nothing inside a module handle to read, print or compare. It cannot be used as a condition — if handle is a compile error saying the type is opaque — and it has no fields.
The only thing you do with one is call an exported function on it, either as a method or through call():
function RENDER()
{
var target := unit_load("/doc/examples/call_target.capy")
print(call(target, "echo", name: "Ada").name, "\n")
}Output
AdaIt is request-local
A handle is valid for the request that created it and must not be stored for a later one — a subsequent request may load a newer source generation. Passing the handle around within a request is fine.
Values crossing a call are the same objects on both sides: the callee works on the value you passed in, and the result it returns is the object you get.
For a single call, unit_call("path:name", input) does the same work without a handle. Load a handle when several calls share one unit.
var target := unit_load("/doc/examples/call_target.capy")
print(target.default_input(), "\n")
Output
default