2
2
-- ports = get_real_portstates(pos): gets if inputs are powered from outside
3
3
-- newport = merge_portstates(state1, state2): just does result = state1 or state2 for every port
4
4
-- 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
6
6
-- lc_update(pos): updates the controller at pos by executing the code
7
7
-- reset_meta (pos, code, errmsg): performs a software-reset, installs new code and prints error messages
8
8
-- reset (pos): performs a hardware reset, turns off all ports
@@ -99,7 +99,7 @@ local setport = function (pos, rule, state)
99
99
end
100
100
end
101
101
102
- local action = function (pos , ports )
102
+ local action = function (pos , ports , digiline_msgs )
103
103
local node = minetest .get_node (pos )
104
104
local name = node .name
105
105
local vports = minetest .registered_nodes [name ].virtual_portstates
@@ -116,6 +116,13 @@ local action = function (pos, ports)
116
116
if ports .c ~= vports .c then setport (pos , rules .c , ports .c ) end
117
117
if ports .d ~= vports .d then setport (pos , rules .d , ports .d ) end
118
118
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
119
126
end
120
127
121
128
---- ----------------
366
373
-- Parsing function --
367
374
---- ------------------
368
375
376
+ lc_digiline_msgs = nil
369
377
lc_update = function (pos , event )
370
378
local meta = minetest .get_meta (pos )
371
379
if not interrupt_allow (meta , event ) then return end
@@ -381,6 +389,7 @@ lc_update = function (pos, event)
381
389
local env = create_environment (pos , mem , event )
382
390
383
391
-- create the sandbox and execute code
392
+ lc_digiline_msgs = {}
384
393
local chunk , msg = create_sandbox (code , env )
385
394
if not chunk then return msg end
386
395
local success , msg = pcall (f )
@@ -389,8 +398,8 @@ lc_update = function (pos, event)
389
398
390
399
save_memory (meta , mem )
391
400
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 )
394
403
end
395
404
396
405
local reset_meta = function (pos , code , errmsg )
409
418
410
419
local reset = function (pos )
411
420
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 }, {} )
413
422
end
414
423
415
424
-- ______
0 commit comments