natiny.script.open_std_safe
natiny.script.open_std_safe(script)
Opens Lua's standard library into another script without the parts that
reach the machine, and points its require() at the mounted folders and
nowhere else. This is what a mod gets.
Parameters
| Name | Type | Description |
|---|---|---|
script |
number |
The script to open the library into |
Example
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("weather mod: " .. natiny.script.get_error(mod))
end
natiny.resource.destroy(source)
What is in, and what is out
| In | Out |
|---|---|
The base library, string, table, math, utf8, coroutine |
io, os, debug |
require, through the mounted folders |
dofile, loadfile, package.loadlib, package.cpath |
io and os between them read and write any path on the machine and start
processes. debug is the way back out of any sandbox built on top of this —
debug.getupvalue reaches into closures a sandbox meant to keep to itself.
package.loadlib loads native code, which has no sandbox at all.
require stays, with two searchers: the package.preload table, which is
where a host puts a module it wants this script to have, and natiny's own,
which reads from the complete resource mount stack. It cannot use require
to read an arbitrary filesystem path, but it can read modules exposed by any
mounted folder.