apply
Cross-runtime dynamic function invocation for Erlang and JavaScript.
Resolve functions by string path in the target runtime and call them,
returning Result(any, String). Error messages share a unified
path/arity + reason style on both targets.
Values
pub fn apply(
raw_path: String,
args: args_tuple,
) -> Result(any, String)
Dynamically invoke a runtime function - the main entry point.
raw_path:"Module:Function"on Erlang,"object.property"on JavaScript.args: must be a tuple; elements are spread as call arguments in order.
Returns an error when args is not a tuple, and a unified error message
when the path is missing, the target is not callable, or the call throws.
apply.apply("erlang:length", #([1, 2, 3])) // Ok(3)
apply.apply("Math.max", #(1, 5)) // Ok(5)
pub fn call_erl(raw: String, arity: Int) -> any
Quick check helper: fetch an Erlang function, crashing on failure.
Prefer apply in real code; when apply is not enough, fetch the function
first and define the call behaviour yourself.
pub fn call_js(raw: String) -> any
Quick check helper: fetch a JS object, crashing on failure.
Prefer apply in real code; when apply is not enough, fetch the object
first and define the call behaviour yourself.
pub fn do_get(
raw_script: String,
erl_arity: Int,
) -> Result(any, String)
Low-level access to a runtime object or function.
On Erlang, exports are checked against erl_arity; on JavaScript the path
is only resolved and arity is ignored. Prefer get_erl_func / get_js_obj.
pub fn get_erl_func(
raw_path: String,
erl_arity: Int,
) -> Result(any, String)
Fetch an Erlang function reference (Erlang target only).
Accepts "Module:Function", or a bare function name which is prefixed
with erlang:. Returns Ok(fun) on success; always returns a runtime
error on the JavaScript target.
Errors include the arity, e.g.
"erlang:length/2 is not exported in erlang (existing arities: 1)".
pub fn get_js_obj(raw_script: String) -> Result(any, String)
Fetch a JavaScript runtime object or function (JavaScript target only).
Takes a dotted path such as "Math.PI" or "console.log".
Always returns a runtime error on the Erlang target.
pub fn platform_name() -> String
The current runtime platform.
Returns "erlang" on the Erlang target and "javascript" on the
JavaScript target.