uce/site/doc/pages/unit_call.txt

33 lines
1.1 KiB
Plaintext

:sig
DTree* unit_call(String file_name, String function_name, DTree* call_param = null)
:params
file_name : UCE file to load and execute
function_name : name of the function to invoke
call_param : optional, call parameter
return value : DTree* returned from function
:desc
Calls an exported function inside another UCE file.
Use `unit_call()` when you need a structured data exchange between units rather than rendered HTML output.
The callee must expose an `EXPORT` function whose name matches `function_name`. Arguments are passed through `call_param`, and the return value is a `DTree*` owned by the callee.
:Example
// export a function
EXPORT DTree* test_func(DTree* call_param)
{
print("HELLO FROM TEST FUNCTION");
return(0);
}
// use that function in another file
unit_call("call_file_funcs.uce", "test_func");
:related
**PHP:** `include`, `require`, or calling a function from an included module, especially when returning arrays or objects instead of rendering a view.
**JavaScript / Node.js:** Importing a module and calling an exported function, or dynamically loading a module and passing structured arguments.
:see
>ob