natiny_script_open_std_safe
void natiny_script_open_std_safe(NatinyScript script);
Opens Lua's standard library into the 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 |
NatinyScript |
The state to open the library into |
Example
NatinyScript mod = natiny_script_create();
natiny_script_open_std_safe(mod);
natiny_script_open_all(mod);
if (natiny_script_run(mod, mod_source) != NATINY_SCRIPT_OK)
return 1;
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.