natiny_script_open_script
void natiny_script_open_script(NatinyScript script);
Makes the script API itself available as natiny.script in the specified
state, so that the script can create, run and call scripts of its own.
Parameters
| Name | Type | Description |
|---|---|---|
script |
NatinyScript |
State whose natiny module receives the script table |
Example
natiny_script_open_std(script);
natiny_script_open_all(script);
if (natiny_script_run(script, source) != NATINY_SCRIPT_OK)
return 1;
Here, source may contain:
local natiny = require("natiny")
-- The game loads a mod itself, with less than it has.
local mod = natiny.script.create()
natiny.script.open_std_safe(mod)
local source = natiny.resource.load("mods/weather/main.lua")
if natiny.script.run(mod, source) ~= natiny.script.OK then
print("weather mod: " .. natiny.script.get_error(mod))
end
natiny.resource.destroy(source)
natiny.script.set(mod, "host.log", print)
natiny.script.call(mod, "on_load", { version = 3 })
What the script gets
Everything natiny.h has under natiny_script_, under the names it has there
with the prefix taken off: create, destroy, run, get_error,
open_std, open_std_safe, fail, set, get, call, call_value, the
five table functions, the four readers and the eight
make_ constructors, plus the status and type constants. The subgroups of this
section document each of them on both sides.
Two are missing, and deliberately: there is no open_all and no
open_<module>. Which engine modules a binary holds is settled by the program
that linked it - a module nobody opened is a module --gc-sections dropped -
so a script has nothing to choose there, and
natiny.script.create gives a new script the modules
the creating one has.