Skip to content

Commit 21550b3

Browse files
committedMar 23, 2013
Explicit tables of luacontroller environment.
1 parent 6983db6 commit 21550b3

File tree

1 file changed

+49
-12
lines changed

1 file changed

+49
-12
lines changed
 

‎mesecons_luacontroller/init.lua

+49-12
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,62 @@ local create_environment = function(pos, mem, event)
187187
vports = {a = vports.a, b = vports.b, c = vports.c, d = vports.d}
188188
local rports = get_real_portstates(pos)
189189

190-
return { print = safeprint,
190+
return {
191+
print = safeprint,
191192
pin = merge_portstates(vports, rports),
192193
port = vports,
193194
interrupt = getinterrupt(pos),
194195
digiline_send = getdigiline_send(pos),
195196
mem = mem,
196197
tostring = tostring,
197198
tonumber = tonumber,
198-
string = tablecopy(string),
199-
math = tablecopy(math),
200-
event = event}
199+
string = {
200+
byte = string.byte,
201+
char = string.char,
202+
find = string.find,
203+
format = string.format,
204+
gmatch = string.gmatch,
205+
gsub = string.gsub,
206+
len = string.len,
207+
lower = string.lower,
208+
match = string.match,
209+
rep = string.rep,
210+
reverse = string.reverse,
211+
sub = string.sub,
212+
},
213+
math = {
214+
abs = math.abs,
215+
acos = math.acos,
216+
asin = math.asin,
217+
atan = math.atan,
218+
atan2 = math.atan2,
219+
ceil = math.ceil,
220+
cos = math.cos,
221+
cosh = math.cosh,
222+
deg = math.deg,
223+
exp = math.exp,
224+
floor = math.floor,
225+
fmod = math.fmod,
226+
frexp = math.frexp,
227+
huge = math.huge,
228+
ldexp = math.ldexp,
229+
log = math.log,
230+
log10 = math.log10,
231+
max = math.max,
232+
min = math.min,
233+
modf = math.modf,
234+
pi = math.pi,
235+
pow = math.pow,
236+
rad = math.rad,
237+
random = math.random,
238+
sin = math.sin,
239+
sinh = math.sinh,
240+
sqrt = math.sqrt,
241+
tan = math.tan,
242+
tanh = math.tanh,
243+
},
244+
event = event,
245+
}
201246
end
202247

203248
local create_sandbox = function (code, env)
@@ -223,14 +268,6 @@ local do_overheat = function (pos, meta)
223268
end
224269
end
225270

226-
local tablecopy = function(t)
227-
local tnew = {}
228-
for key, value in pairs(t) do
229-
tnew[key] = value
230-
end
231-
return tnew
232-
end
233-
234271
local load_memory = function(meta)
235272
return minetest.deserialize(meta:get_string("lc_memory")) or {}
236273
end

0 commit comments

Comments
 (0)
Please sign in to comment.