natiny.script.open_std

Lua
natiny.script.open_std(script)

Opens Lua's own standard library into another script - all of it - and points its require() at the mounted folders.

Parameters

Name Type Description
script number The script to open the library into

Example

Lua
local natiny = require("natiny")

local tools = natiny.script.create()
natiny.script.open_std(tools)

What the script gets

The complete standard library: string, table, math, utf8, coroutine, package, and io, os and debug with them. This is the set a program the player wrote gets, on the understanding that it is their program running on their machine.

It also does two things the plain library does not:

  • require() reads through the resource stack. A require("game.state") becomes game/state.lua looked up with natiny.resource.load, so it is the same name whether that is a loose file, an entry in a pack, or the same name in a mod mounted over the top. Lua's own searchers are left in place and run first, so a file lying where Lua can open it is still found the way it was.
  • require("natiny") returns the module table. Not a global: the script says local natiny = require("natiny") and nothing appears under a name it did not ask for.