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, digiline_msgs ): Applies new portstates to a luacontroller at pos, and sends pending digiline messages
5
+ -- action(pos, ports): Applies new portstates to a luacontroller at pos
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 , digiline_msgs )
102
+ local action = function (pos , ports )
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,13 +116,6 @@ local action = function (pos, ports, digiline_msgs)
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
126
119
end
127
120
128
121
---- ----------------
@@ -241,6 +234,16 @@ local gettimer = function(pos)
241
234
return timer
242
235
end
243
236
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
+
244
247
local create_environment = function (pos , mem , event )
245
248
-- Gather variables for the environment
246
249
local vports = minetest .registered_nodes [minetest .get_node (pos ).name ].virtual_portstates
@@ -253,10 +256,7 @@ local create_environment = function(pos, mem, event)
253
256
port = vports ,
254
257
interrupt = getinterrupt (pos ),
255
258
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 ),
260
260
mem = mem ,
261
261
tostring = tostring ,
262
262
tonumber = tonumber ,
373
373
-- Parsing function --
374
374
---- ------------------
375
375
376
- lc_digiline_msgs = nil
377
376
lc_update = function (pos , event )
378
377
local meta = minetest .get_meta (pos )
379
378
if not interrupt_allow (meta , event ) then return end
@@ -385,11 +384,10 @@ lc_update = function (pos, event)
385
384
386
385
-- make sure code is ok and create environment
387
386
local prohibited = code_prohibited (code )
388
- if prohibited then return prohibited end
387
+ if prohibited then return prohibited end
389
388
local env = create_environment (pos , mem , event )
390
389
391
390
-- create the sandbox and execute code
392
- lc_digiline_msgs = {}
393
391
local chunk , msg = create_sandbox (code , env )
394
392
if not chunk then return msg end
395
393
local success , msg = pcall (f )
@@ -398,8 +396,8 @@ lc_update = function (pos, event)
398
396
399
397
save_memory (meta , mem )
400
398
401
- -- Actually set the ports and send digiline messages
402
- minetest .after (0 , action , pos , env .port , lc_digiline_msgs )
399
+ -- Actually set the ports
400
+ minetest .after (0 , action , pos , env .port )
403
401
end
404
402
405
403
local reset_meta = function (pos , code , errmsg )
418
416
419
417
local reset = function (pos )
420
418
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 })
422
420
end
423
421
424
422
-- ______
0 commit comments