mirror of
https://github.com/edubart/otclient.git
synced 2025-11-30 23:26:51 +01:00
Module sandboxing system
Sandboxing makes module scripts run inside an isolated lua environments, making more easier and secure to script Move and rework TextMessage using the new sandbox system
This commit is contained in:
@@ -110,9 +110,34 @@ function extends(base)
|
||||
return derived
|
||||
end
|
||||
|
||||
function export(what, key)
|
||||
if key ~= nil then
|
||||
_G[key] = what
|
||||
else
|
||||
for k,v in pairs(what) do
|
||||
_G[k] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function unexport(key)
|
||||
if type(key) == 'table' then
|
||||
for _k,v in pairs(key) do
|
||||
_G[v] = nil
|
||||
end
|
||||
else
|
||||
_G[key] = nil
|
||||
end
|
||||
end
|
||||
|
||||
function sandbox(what)
|
||||
what = what or 2
|
||||
setfenv(what, newenv())
|
||||
end
|
||||
|
||||
function newenv()
|
||||
local env = { }
|
||||
setmetatable(env, { __index = _G} )
|
||||
setmetatable(env, { __index = getfenv() } )
|
||||
return env
|
||||
end
|
||||
|
||||
@@ -157,13 +182,6 @@ function toboolean(str)
|
||||
return false
|
||||
end
|
||||
|
||||
local oldtonumber = tonumber
|
||||
|
||||
function tonumber(v)
|
||||
if v == nil then return 0 end
|
||||
return oldtonumber(v)
|
||||
end
|
||||
|
||||
function signalcall(param, ...)
|
||||
if type(param) == 'function' then
|
||||
return param(...)
|
||||
|
||||
Reference in New Issue
Block a user