natiny_script_call
bool natiny_script_call(NatinyScript script, const char* path,
const NatinyScriptValue* args, uint32_t count,
NatinyScriptValue* results, uint32_t* result_count);
Calls the function under a dotted name.
Parameters
| Name | Type | Description |
|---|---|---|
script |
NatinyScript |
The state to call in |
path |
const char* |
Dotted name of the function |
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* |
Array with room for NATINY_SCRIPT_MAX_RESULTS results, or NULL to discard all results |
result_count |
uint32_t* |
Receives the number written to results; set to 0 on failure or when results is NULL; may be NULL |
Returns
| Type | Description |
|---|---|
bool |
true when the call ran to the end; false when the name is missing, does not hold a function, or the call raised an error |
natiny_script_get_error holds the message on
false.
Example
NatinyScriptValue args[2];
NatinyScriptValue results[NATINY_SCRIPT_MAX_RESULTS];
uint32_t got = 0;
args[0] = natiny_script_make_string("autosave");
args[1] = natiny_script_make_number(3);
if (natiny_script_call(script, "game.save", args, 2, results, &got)) {
if (got > 0 && natiny_script_to_bool(results[0]))
printf("saved\n");
} else {
fprintf(stderr, "save failed: %s\n", natiny_script_get_error(script));
}
Notes
- Result strings, tables and functions are borrowed: valid until the next
natiny_script_run,natiny_script_callornatiny_script_call_valueon that state, and nothing to release. - Whatever an earlier operation on this state lent you ends with this call -
but only after the arguments are on the stack, so a table from
natiny_script_getornatiny_script_make_tablecan be passed straight in.natiny_script_holdis what keeps something longer.