Working
This commit is contained in:
41
luprex/syslua/model.lua
Normal file
41
luprex/syslua/model.lua
Normal file
@@ -0,0 +1,41 @@
|
||||
local model=class('model')
|
||||
local globaldb=class('globaldb')
|
||||
|
||||
-- The global environment contents for a model. A list of the builtin
|
||||
-- functions and classes that get installed in the global environment of
|
||||
-- a world model.
|
||||
--
|
||||
-- This barely counts as 'sandboxing' - it's more just a mechanism to
|
||||
-- keep the user from unintentionally thinking that some functionality is
|
||||
-- available when it's not. For true sandboxing, you need to not import
|
||||
-- functions into the lua interpreter at all.
|
||||
--
|
||||
-- Omitted from this list: debug, dofile, getfenv, io, jit,
|
||||
-- load, loadfile, loadstring, module, newproxy, os, package,
|
||||
-- pcall, require, xpcall
|
||||
--
|
||||
|
||||
model.global_contents = { "assert", "bit", "error", "getmetatable", "inspect",
|
||||
"ipairs", "math", "next", "pairs", "print", "rawequal", "rawget", "rawset",
|
||||
"select", "setmetatable", "tonumber", "tostring", "type", "unpack" }
|
||||
|
||||
-- make a world model.
|
||||
--
|
||||
function model.make()
|
||||
genv = {}
|
||||
genv._G = genv
|
||||
meta = {}
|
||||
meta.class_db = classdb.create()
|
||||
meta.global_db = globaldb.create()
|
||||
meta.source_db = {}
|
||||
meta.tangible_db = {}
|
||||
meta.__newindex = function() error("world model global environment is read-only") end
|
||||
-- meta.__metatable = false
|
||||
genv.class = classdb.accessor(meta.class_db)
|
||||
genv.global = make_global_accessor(meta.global_db)
|
||||
for i,name in ipairs(world.global_contents) do
|
||||
genv[name] = _G[name]
|
||||
end
|
||||
setmetatable(genv, meta)
|
||||
return genv
|
||||
end
|
||||
Reference in New Issue
Block a user