Skip to content

Commit b50721c

Browse files
author
Jeija
committedMar 16, 2014
Merge branch 'digiline-non-reentrant' of https://github.com/CiaranG/minetest-mod-mesecons into CiaranG-digiline-non-reentrant
Conflicts: mesecons_luacontroller/init.lua
2 parents 38ff900 + 5002315 commit b50721c

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed
 

‎mesecons_luacontroller/init.lua

+14-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
-- ports = get_real_portstates(pos): gets if inputs are powered from outside
33
-- newport = merge_portstates(state1, state2): just does result = state1 or state2 for every port
44
-- action_setports(pos, rule, state): activates/deactivates the mesecons according to the portstates (helper for action)
5-
-- action(pos, ports): Applies new portstates to a luacontroller at pos
5+
-- action(pos, ports, digiline_msgs): Applies new portstates to a luacontroller at pos, and sends pending digiline messages
66
-- lc_update(pos): updates the controller at pos by executing the code
77
-- reset_meta (pos, code, errmsg): performs a software-reset, installs new code and prints error messages
88
-- reset (pos): performs a hardware reset, turns off all ports
@@ -99,7 +99,7 @@ local setport = function (pos, rule, state)
9999
end
100100
end
101101

102-
local action = function (pos, ports)
102+
local action = function (pos, ports, digiline_msgs)
103103
local node = minetest.get_node(pos)
104104
local name = node.name
105105
local vports = minetest.registered_nodes[name].virtual_portstates
@@ -116,6 +116,13 @@ local action = function (pos, ports)
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
119126
end
120127

121128
--------------------
@@ -366,6 +373,7 @@ end
366373
-- Parsing function --
367374
----------------------
368375

376+
lc_digiline_msgs = nil
369377
lc_update = function (pos, event)
370378
local meta = minetest.get_meta(pos)
371379
if not interrupt_allow(meta, event) then return end
@@ -381,6 +389,7 @@ lc_update = function (pos, event)
381389
local env = create_environment(pos, mem, event)
382390

383391
-- create the sandbox and execute code
392+
lc_digiline_msgs = {}
384393
local chunk, msg = create_sandbox (code, env)
385394
if not chunk then return msg end
386395
local success, msg = pcall(f)
@@ -389,8 +398,8 @@ lc_update = function (pos, event)
389398

390399
save_memory(meta, mem)
391400

392-
-- Actually set the ports
393-
minetest.after(0, action, pos, env.port)
401+
-- Actually set the ports and send digiline messages
402+
minetest.after(0, action, pos, env.port, lc_digiline_msgs)
394403
end
395404

396405
local reset_meta = function(pos, code, errmsg)
@@ -409,7 +418,7 @@ end
409418

410419
local reset = function (pos)
411420
minetest.get_meta(pos):set_string("lc_interrupts", "")
412-
action(pos, {a=false, b=false, c=false, d=false}, true)
421+
action(pos, {a=false, b=false, c=false, d=false}, {})
413422
end
414423

415424
-- ______

0 commit comments

Comments
 (0)
Please sign in to comment.