forked from minetest-mods/mesecons
		
	Improve the LuaController
Changes: * Stops code after a certain number of instructions. * Allows functions, due to instruction counting. * Allows loops and goto with non-JIT Lua (LuaJIT doesn't count looping as an instruction, allowing infinite loops), due to instruction counting. * Removes string matching functions as they can be slow. * Adds some safe functions. * Limits the amount of printing that can be done (to prevent console flooding). * Code cleanup. * More...
This commit is contained in:
		@@ -1,18 +1,13 @@
 | 
			
		||||
minetest.swap_node = minetest.swap_node or function(pos, node)
 | 
			
		||||
	local data = minetest.get_meta(pos):to_table()
 | 
			
		||||
	minetest.add_node(pos, node)
 | 
			
		||||
	minetest.get_meta(pos):from_table(data)
 | 
			
		||||
end
 | 
			
		||||
local rules = {
 | 
			
		||||
	a = {x = -1, y = 0, z =  0, name="A"},
 | 
			
		||||
	b = {x =  0, y = 0, z =  1, name="B"},
 | 
			
		||||
	c = {x =  1, y = 0, z =  0, name="C"},
 | 
			
		||||
	d = {x =  0, y = 0, z = -1, name="D"},
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
local rules = {}
 | 
			
		||||
rules.a = {x = -1, y = 0, z =  0, name="A"}
 | 
			
		||||
rules.b = {x =  0, y = 0, z =  1, name="B"}
 | 
			
		||||
rules.c = {x =  1, y = 0, z =  0, name="C"}
 | 
			
		||||
rules.d = {x =  0, y = 0, z = -1, name="D"}
 | 
			
		||||
 | 
			
		||||
function legacy_update_ports(pos)
 | 
			
		||||
function mesecon.legacy_update_ports(pos)
 | 
			
		||||
	local meta = minetest.get_meta(pos)
 | 
			
		||||
	L = {
 | 
			
		||||
	local ports = {
 | 
			
		||||
		a = mesecon:is_power_on(mesecon:addPosRule(pos, rules.a),
 | 
			
		||||
			mesecon:invertRule(rules.a)) and
 | 
			
		||||
			mesecon:rules_link(mesecon:addPosRule(pos, rules.a), pos),
 | 
			
		||||
@@ -26,7 +21,12 @@ function legacy_update_ports(pos)
 | 
			
		||||
			mesecon:invertRule(rules.d)) and
 | 
			
		||||
			mesecon:rules_link(mesecon:addPosRule(pos, rules.d), pos),
 | 
			
		||||
	}
 | 
			
		||||
	local n = (L.a and 1 or 0) + (L.b and 2 or 0) + (L.c and 4 or 0) + (L.d and 8 or 0) + 1
 | 
			
		||||
	local n =
 | 
			
		||||
		(ports.a and 1 or 0) +
 | 
			
		||||
		(ports.b and 2 or 0) +
 | 
			
		||||
		(ports.c and 4 or 0) +
 | 
			
		||||
		(ports.d and 8 or 0) + 1
 | 
			
		||||
	meta:set_int("real_portstates", n)
 | 
			
		||||
	return L
 | 
			
		||||
	return ports
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user