Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- DixBox
- -- a simple Lua sandbox, mainly for CC
- --==========[COPY-PASTE DIX PLUGIN DESCRIPTOR]==========--
- local versionString="0.1"
- local pluginName="sandbox"
- local pluginAuthor="MarcusD"
- local isColorNeeded=false
- dixmod(pluginName, pluginAuthor, versionString, isColorNeeded)
- --==========[COPY-PASTE DIX PLUGIN DESCRIPTOR]==========--
- function new(func, sandenv, ignore, fenv)
- if not sandenv then sandenv = {} end
- if not ignore then ignore = {} end
- if not fenv then fenv = getfenv() end
- local sandenv_meta = {}
- function sandenv_meta:__index(k)
- local thing = rawget(sandenv, k)
- if ignore[k] then return thing end
- return thing ~= nil and thing or fenv[k]
- end
- function sandenv_meta:__newindex(k,v)
- rawset(sandenv, k, v)
- end
- setmetatable(sandenv, sandenv_meta)
- local cor = nil
- if type(func) == "function" then
- setfenv(func, sandenv)
- cor = coroutine.create(func)
- end
- return
- {
- getsand = function()
- return sandenv
- end,
- getsand_meta = function()
- return sandenv_meta
- end,
- reset_meta = function()
- return setmetatable(sandenv, sandenv_meta)
- end,
- setsand = function(wat)
- if type(wat) ~= "table" then error("Not a table") end
- sandenv = wat
- end,
- setsand_meta = function(wat)
- if type(wat) ~= "table" then error("Not a table") end
- sandenv_meta = wat
- end,
- setignore = function(k, b)
- if type(k) ~= "string" or type(b) ~= "boolean" then error("Expected string, boolean") end
- if k == "" or k:match("[^%s]*") ~= k then error("Key must be non-empty, nor containing whitespace") end
- ignore[k] = b
- end,
- getignore = function(k)
- if type(k) ~= "string" then error("Expected string") end
- if k == "" or k:match("[^%s]*") ~= k then error("Key must be non-empty, nor containing whitespace") end
- return ignore[k]
- end,
- getfuncenv = function()
- return fenv
- end,
- getroutine = function()
- return cor
- end,
- run = function(...)
- return coroutine.resume(cor, ...)
- end,
- unyield = function(...)
- return coroutine.resume(cor, coroutine.yield(...))
- end
- }
- end
Advertisement
Add Comment
Please, Sign In to add comment