Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit dac05e4

Browse files
author
Jeija
committedMar 19, 2014
Improve and clean up luacontroller digiline_send on globalstep feature
1 parent b50721c commit dac05e4

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed
 

‎mesecons_luacontroller/init.lua

+14-16
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,6 @@ local action = function (pos, ports, digiline_msgs)
116116
if ports.c ~= vports.c then setport(pos, rules.c, ports.c) end
117117
if ports.d ~= vports.d then setport(pos, rules.d, ports.d) end
118118
end
119-
120-
if digiline then
121-
for i = 1, #digiline_msgs do
122-
digiline:receptor_send(pos, digiline.rules.default,
123-
digiline_msgs[i].channel, digiline_msgs[i].msg)
124-
end
125-
end
126119
end
127120

128121
--------------------
@@ -241,6 +234,16 @@ local gettimer = function(pos)
241234
return timer
242235
end
243236

237+
local getdigiline_send = function(pos)
238+
if not digiline then return end
239+
-- Send messages on next serverstep
240+
return function(channel, msg)
241+
minetest.after(0, function()
242+
digiline:receptor_send(pos, digiline.rules.default, channel, msg)
243+
end)
244+
end
245+
end
246+
244247
local create_environment = function(pos, mem, event)
245248
-- Gather variables for the environment
246249
local vports = minetest.registered_nodes[minetest.get_node(pos).name].virtual_portstates
@@ -253,10 +256,7 @@ local create_environment = function(pos, mem, event)
253256
port = vports,
254257
interrupt = getinterrupt(pos),
255258
timer = gettimer(pos),
256-
digiline_msgs = {},
257-
digiline_send = function(channel, msg)
258-
table.insert(lc_digiline_msgs, {["channel"]=channel, ["msg"]=msg})
259-
end,
259+
digiline_send = getdigiline_send(pos),
260260
mem = mem,
261261
tostring = tostring,
262262
tonumber = tonumber,
@@ -373,7 +373,6 @@ end
373373
-- Parsing function --
374374
----------------------
375375

376-
lc_digiline_msgs = nil
377376
lc_update = function (pos, event)
378377
local meta = minetest.get_meta(pos)
379378
if not interrupt_allow(meta, event) then return end
@@ -385,11 +384,10 @@ lc_update = function (pos, event)
385384

386385
-- make sure code is ok and create environment
387386
local prohibited = code_prohibited(code)
388-
if prohibited then return prohibited end
387+
if prohibited then return prohibited end
389388
local env = create_environment(pos, mem, event)
390389

391390
-- create the sandbox and execute code
392-
lc_digiline_msgs = {}
393391
local chunk, msg = create_sandbox (code, env)
394392
if not chunk then return msg end
395393
local success, msg = pcall(f)
@@ -399,7 +397,7 @@ lc_update = function (pos, event)
399397
save_memory(meta, mem)
400398

401399
-- Actually set the ports and send digiline messages
402-
minetest.after(0, action, pos, env.port, lc_digiline_msgs)
400+
minetest.after(0, action, pos, env.port)
403401
end
404402

405403
local reset_meta = function(pos, code, errmsg)
@@ -418,7 +416,7 @@ end
418416

419417
local reset = function (pos)
420418
minetest.get_meta(pos):set_string("lc_interrupts", "")
421-
action(pos, {a=false, b=false, c=false, d=false}, {})
419+
action(pos, {a=false, b=false, c=false, d=false})
422420
end
423421

424422
-- ______

0 commit comments

Comments
 (0)
Please sign in to comment.