natiny.script.create

Lua
natiny.script.create() -> script

Makes a second script and returns the handle naming it. The new script starts with the engine modules this one has and no standard library: what Lua's own library it gets is the next thing you say.

Returns

Type Description
number The new script, or 0 when the interpreter could not be made

Example

Lua
local natiny = require("natiny")

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("mod disabled: " .. natiny.script.get_error(mod))
end
natiny.resource.destroy(source)

Why the modules come along

In C the new state starts empty and the program opens what it wants into it. A script cannot do that, and is not asked to: which engine modules exist at all was settled when the program was linked - a module nobody opened is a module the linker dropped - so there is no natiny.script.open_render() to call and nothing a script could add that is not already there.

So the new script gets the set this one is looking at, which is the set the program decided to ship. What is still a choice is Lua's own library, and open_std_safe is how a game gives a mod less than it has itself.