natiny_script_hold
NatinyScriptValue natiny_script_hold(NatinyScript script, NatinyScriptValue value);
Keeps a value past its loan. Everything a script hands out is valid until the
next call into it; the value this returns stays valid until
natiny_script_release.
Parameters
| Name | Type | Description |
|---|---|---|
script |
NatinyScript |
The state the value belongs to |
value |
NatinyScriptValue |
Any value - from natiny_script_get, a call's results, a callback's arguments, natiny_script_make_table |
Returns
| Type | Description |
|---|---|
NatinyScriptValue |
The kept value; NATINY_SCRIPT_NIL when a table or function is no longer valid |
Example
A script registers a callback, and C calls it later:
static NatinyScriptValue on_event;
static uint32_t register_on_event(NatinyScript script,
const NatinyScriptValue* args, uint32_t count,
NatinyScriptValue* results) {
natiny_script_release(script, on_event);
on_event = natiny_script_hold(script, args[0]);
return 0;
}
/* later, as often as needed */
natiny_script_call_value(script, on_event, &event, 1, NULL, NULL);
host.on_event(function(e) print("event", e) end)