natiny_script_call_value
bool natiny_script_call_value(NatinyScript script, NatinyScriptValue function,
const NatinyScriptValue* args, uint32_t count,
NatinyScriptValue* results, uint32_t* result_count);
Calls a function value. The same operation as natiny_script_call
without a dotted name to resolve.
Parameters
| Name | Type | Description |
|---|---|---|
script |
NatinyScript |
The state the function belongs to |
function |
NatinyScriptValue |
The function to call |
args |
const NatinyScriptValue* |
Array of count arguments; may be NULL only when count is 0 |
count |
uint32_t |
How many; anything past NATINY_SCRIPT_MAX_ARGS is dropped |
results |
NatinyScriptValue* |
Room for NATINY_SCRIPT_MAX_RESULTS results, or NULL to discard them |
result_count |
uint32_t* |
Receives the number written to results; may be NULL |
Returns
| Type | Description |
|---|---|
bool |
true when the call ran to the end; false when function is not a function, is no longer valid, or the call raised |
natiny_script_get_error holds the message on
false.
Example
NatinyScriptValue on_frame =
natiny_script_hold(script, natiny_script_get(script, "game.on_frame"));
/* every frame */
NatinyScriptValue dt_arg = natiny_script_make_number(dt);
if (!natiny_script_call_value(script, on_frame, &dt_arg, 1, NULL, NULL))
fprintf(stderr, "on_frame: %s\n", natiny_script_get_error(script));
/* at shutdown */
natiny_script_release(script, on_frame);
Notes
- A borrowed function works too - one read with
natiny_script_getand called before anything else enters the script. The call ends the loan only after the function and its arguments are on the stack. - For a function called every frame,
natiny_script_holdit once: a held function is valid until you release it.