Export Functions Metadata to JSON
Engine::gen_fn_metadata_to_json
Engine::gen_fn_metadata_with_ast_to_json
As part of a reflections API, Engine::gen_fn_metadata_to_json
and the corresponding
Engine::gen_fn_metadata_with_ast_to_json
export the full list of functions metadata
in JSON format.
The [`metadata`] feature is required for this API, which also pulls in the
[`serde_json`](https://crates.io/crates/serde_json) crate.
Sources
Functions from the following sources are included:
- Script-defined functions in an
AST
(forEngine::gen_fn_metadata_with_ast_to_json
) - Native Rust functions registered into the global namespace via the
Engine::register_XXX
API - Public (i.e. non-
private
) functions (native Rust or Rhai scripted) in static modules registered viaEngine::register_static_module
- Native Rust functions in external packages registered via
Engine::register_global_module
- Native Rust functions in built-in packages (optional)
JSON Schema
The JSON schema used to hold functions metadata is very simple, containing a nested structure of
modules
and a list of functions
.
Modules Schema
{
"modules":
{
/* namespace 'sub_module_1' */
"sub_module_1":
{
"modules":
{
/* namespace 'sub_module_1::sub_sub_module_A' */
"sub_sub_module_A":
{
/* functions exported in 'sub_module_1::sub_sub_module_A' */
"functions":
[
{ ... function metadata ... },
{ ... function metadata ... },
{ ... function metadata ... },
{ ... function metadata ... },
...
]
},
/* namespace 'sub_module_1::sub_sub_module_B' */
"sub_sub_module_B":
{
...
}
}
},
"sub_module_2":
{
...
},
...
},
/* functions registered globally or in the 'AST' */
"functions":
[
{ ... function metadata ... },
{ ... function metadata ... },
{ ... function metadata ... },
{ ... function metadata ... },
...
]
}
Function Metadata Schema
{
"baseHash": 9876543210, /* partial hash with only number of parameters */
"fullHash": 1234567890, /* full hash with actual parameter types */
"namespace": "internal" | "global",
"access": "public" | "private",
"name": "fn_name",
"type": "native" | "script",
"numParams": 42, /* number of parameters */
"params": /* omitted if no parameters */
[
{ "name": "param_1", "type": "type_1" },
{ "name": "param_2" }, /* no type name */
{ "type": "type_3" }, /* no parameter name */
...
],
"returnType": "ret_type", /* omitted if () or unknown */
"signature": "[private] fn_name(param_1: type_1, param_2, _: type_3) -> ret_type",
"docComments": /* omitted if none */
[
"/// doc-comment line 1",
"/// doc-comment line 2",
"/** doc-comment block */",
...
]
}