natiny_script_run
int natiny_script_run(NatinyScript script, NatinyResource source);
Compiles the contents of source and runs it in script. Control does not
come back until the script returns - so a game whose entry script calls
natiny.backend.loop() spends its whole run inside this call.
Parameters
| Name | Type | Description |
|---|---|---|
script |
NatinyScript |
The state to run in |
source |
NatinyResource |
Lua source bytes to compile; the resource remains owned by the caller |
Returns
| Type | Description |
|---|---|
int |
NATINY_SCRIPT_OK after successful execution, NATINY_SCRIPT_LOAD_ERROR when the state or source is invalid or the source does not compile, or NATINY_SCRIPT_RUN_ERROR when execution raises an error |
natiny_script_get_error holds the message for either failure.
Example
NatinyResource source = natiny_resource_load("main.lua");
if (!source) return 1;
switch (natiny_script_run(script, source)) {
case NATINY_SCRIPT_LOAD_ERROR:
fprintf(stderr, "will not compile: %s\n",
natiny_script_get_error(script));
break;
case NATINY_SCRIPT_RUN_ERROR:
fprintf(stderr, "failed: %s\n", natiny_script_get_error(script));
break;
}
natiny_resource_destroy(source);