Back to API reference

Module manager

Initially global Lua environment has no entries but to module manager module. This is designed to allow some API customization and to simplify sandboxing.

Here's the common API setup for main environment:

local G = module_manager.get_G ()

-- Register all modules into global environment:
module_manager.register_all (G)

-- Unpack 'base' into global environment:
for k, v in base.pairs (base) do
   G[k] = v

And here's an example of sandbox API setup:

local get = module_manager.get
local sandbox_env = {
   mat4 = get ("mat4"), -- NOTE: we build new module not allowing
                        -- to pollute 'mat4' from global environment
   dmat4 = get ("dmat4"),
   string = get ("string"),
   print = print, -- Function cannot be polluted
                  -- so we don't need to rebuild 'base'

local sandbox_func = assert (loadstring ([[
local m1 = mat4.identity ()
print (m1)
local m2 = dmat4.identity ()*3
print (m2)

setfenv (sandbox_func, sandbox_env)
sandbox_func ()

See the module reference page:

Back to API reference