Lots of work on LuaStack

This commit is contained in:
2020-11-27 13:21:07 -05:00
parent f690fb147b
commit 455ba5df87
19 changed files with 715 additions and 527 deletions

View File

@@ -4,7 +4,6 @@
#
inspect.lua
globaldb.lua
model.lua

View File

@@ -1,22 +0,0 @@
local globaldb=class('globaldb')
function globaldb.get(db, key)
local result = db[key]
if type(result) == 'table' then
return result
else
result = {}
db[key] = result
end
return result
end
function globaldb.accessor(db)
return function(key)
return globaldb.get(db, key)
end
end
function globaldb.create()
return {}
end

View File

@@ -333,7 +333,7 @@ function inspect.inspect(root, options)
return table.concat(inspector.buffer)
end
function inspect.iprint(...)
function inspect.pprint(...)
local n = select("#", ...)
for i = 1,n do
local v = select(i, ...)
@@ -341,4 +341,4 @@ function inspect.iprint(...)
end
end
_G.iprint = inspect.iprint
_G.pprint = inspect.pprint

View File

@@ -1,41 +0,0 @@
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