Skip to content

Commit

Permalink
Explicit tables of luacontroller environment.
Browse files Browse the repository at this point in the history
  • Loading branch information
Uberi committed Mar 23, 2013
1 parent 6983db6 commit 21550b3
Showing 1 changed file with 49 additions and 12 deletions.
61 changes: 49 additions & 12 deletions mesecons_luacontroller/init.lua
Expand Up @@ -187,17 +187,62 @@ local create_environment = function(pos, mem, event)
vports = {a = vports.a, b = vports.b, c = vports.c, d = vports.d}
local rports = get_real_portstates(pos)

return { print = safeprint,
return {
print = safeprint,
pin = merge_portstates(vports, rports),
port = vports,
interrupt = getinterrupt(pos),
digiline_send = getdigiline_send(pos),
mem = mem,
tostring = tostring,
tonumber = tonumber,
string = tablecopy(string),
math = tablecopy(math),
event = event}
string = {
byte = string.byte,
char = string.char,
find = string.find,
format = string.format,
gmatch = string.gmatch,
gsub = string.gsub,
len = string.len,
lower = string.lower,
match = string.match,
rep = string.rep,
reverse = string.reverse,
sub = string.sub,
},
math = {
abs = math.abs,
acos = math.acos,
asin = math.asin,
atan = math.atan,
atan2 = math.atan2,
ceil = math.ceil,
cos = math.cos,
cosh = math.cosh,
deg = math.deg,
exp = math.exp,
floor = math.floor,
fmod = math.fmod,
frexp = math.frexp,
huge = math.huge,
ldexp = math.ldexp,
log = math.log,
log10 = math.log10,
max = math.max,
min = math.min,
modf = math.modf,
pi = math.pi,
pow = math.pow,
rad = math.rad,
random = math.random,
sin = math.sin,
sinh = math.sinh,
sqrt = math.sqrt,
tan = math.tan,
tanh = math.tanh,
},
event = event,
}
end

local create_sandbox = function (code, env)
Expand All @@ -223,14 +268,6 @@ local do_overheat = function (pos, meta)
end
end

local tablecopy = function(t)
local tnew = {}
for key, value in pairs(t) do
tnew[key] = value
end
return tnew
end

local load_memory = function(meta)
return minetest.deserialize(meta:get_string("lc_memory")) or {}
end
Expand Down

0 comments on commit 21550b3

Please sign in to comment.