mirror of
https://github.com/minetest-mods/mesecons.git
synced 2025-06-28 05:50:17 +02:00
Add .luacheckrc and fix issues it pointed out (#589)
This commit is contained in:
committed by
GitHub
parent
c9dd323207
commit
fb255d292e
@ -102,7 +102,7 @@ minetest.register_node(nodename, {
|
||||
for i=1, EEPROM_SIZE+1 do r=r.."0" end --Generate a string with EEPROM_SIZE*"0"
|
||||
meta:set_string("eeprom", r)
|
||||
end,
|
||||
on_receive_fields = function(pos, formanme, fields, sender)
|
||||
on_receive_fields = function(pos, _, fields, sender)
|
||||
local player_name = sender:get_player_name()
|
||||
if minetest.is_protected(pos, player_name) and
|
||||
not minetest.check_player_privs(player_name, {protection_bypass=true}) then
|
||||
@ -225,7 +225,6 @@ yc.parsecode = function(code, pos)
|
||||
local Lreal = yc.get_real_portstates(pos)
|
||||
local Lvirtual = yc.get_virtual_portstates(pos)
|
||||
if Lvirtual == nil then return nil end
|
||||
local c
|
||||
local eeprom = meta:get_string("eeprom")
|
||||
while true do
|
||||
local command, params
|
||||
@ -251,9 +250,9 @@ yc.parsecode = function(code, pos)
|
||||
if not params then return nil end
|
||||
end
|
||||
if command == "on" then
|
||||
L = yc.command_on (params, Lvirtual)
|
||||
Lvirtual = yc.command_on (params, Lvirtual)
|
||||
elseif command == "off" then
|
||||
L = yc.command_off(params, Lvirtual)
|
||||
Lvirtual = yc.command_off(params, Lvirtual)
|
||||
elseif command == "print" then
|
||||
local su = yc.command_print(params, eeprom, yc.merge_portstates(Lreal, Lvirtual))
|
||||
if su ~= true then return nil end
|
||||
@ -384,7 +383,6 @@ end
|
||||
|
||||
--Commands
|
||||
yc.command_on = function(params, L)
|
||||
local rules = {}
|
||||
for i, port in ipairs(params) do
|
||||
L = yc.set_portstate (port, true, L)
|
||||
end
|
||||
@ -392,7 +390,6 @@ yc.command_on = function(params, L)
|
||||
end
|
||||
|
||||
yc.command_off = function(params, L)
|
||||
local rules = {}
|
||||
for i, port in ipairs(params) do
|
||||
L = yc.set_portstate (port, false, L)
|
||||
end
|
||||
@ -405,7 +402,7 @@ yc.command_print = function(params, eeprom, L)
|
||||
if param:sub(1,1) == '"' and param:sub(#param, #param) == '"' then
|
||||
s = s..param:sub(2, #param-1)
|
||||
else
|
||||
r = yc.command_parsecondition(param, L, eeprom)
|
||||
local r = yc.command_parsecondition(param, L, eeprom)
|
||||
if r == "1" or r == "0" then
|
||||
s = s..r
|
||||
else return nil end
|
||||
@ -469,8 +466,8 @@ yc.command_after_execute = function(params)
|
||||
if yc.parsecode(params.code, params.pos) == nil then
|
||||
meta:set_string("infotext", "Code in after() not valid!")
|
||||
else
|
||||
if code ~= nil then
|
||||
meta:set_string("infotext", "Working Microcontroller\n"..code)
|
||||
if params.code ~= nil then
|
||||
meta:set_string("infotext", "Working Microcontroller\n"..params.code)
|
||||
else
|
||||
meta:set_string("infotext", "Working Microcontroller")
|
||||
end
|
||||
@ -543,8 +540,8 @@ yc.command_parsecondition = function(cond, L, eeprom)
|
||||
cond = string.gsub(cond, "!0", "1")
|
||||
cond = string.gsub(cond, "!1", "0")
|
||||
|
||||
local i = 2
|
||||
local l = string.len(cond)
|
||||
i = 2
|
||||
l = string.len(cond)
|
||||
while i<=l do
|
||||
local s = cond:sub(i,i)
|
||||
local b = tonumber(cond:sub(i-1, i-1))
|
||||
@ -553,8 +550,7 @@ yc.command_parsecondition = function(cond, L, eeprom)
|
||||
if s == "=" then
|
||||
if a==nil then return nil end
|
||||
if b==nil then return nil end
|
||||
if a == b then buf = "1" end
|
||||
if a ~= b then buf = "0" end
|
||||
local buf = a == b and "1" or "0"
|
||||
cond = string.gsub(cond, b..s..a, buf)
|
||||
i = 1
|
||||
l = string.len(cond)
|
||||
@ -562,8 +558,8 @@ yc.command_parsecondition = function(cond, L, eeprom)
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
local i = 2
|
||||
local l = string.len(cond)
|
||||
i = 2
|
||||
l = string.len(cond)
|
||||
while i<=l do
|
||||
local s = cond:sub(i,i)
|
||||
local b = tonumber(cond:sub(i-1, i-1))
|
||||
@ -659,7 +655,7 @@ yc.set_portstate = function(port, state, L)
|
||||
return L
|
||||
end
|
||||
|
||||
yc.update_real_portstates = function(pos, node, rulename, newstate)
|
||||
yc.update_real_portstates = function(pos, _, rulename, newstate)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if rulename == nil then
|
||||
meta:set_int("real_portstates", 1)
|
||||
@ -696,7 +692,7 @@ end
|
||||
|
||||
yc.get_virtual_portstates = function(pos) -- portstates according to the name
|
||||
local name = minetest.get_node(pos).name
|
||||
local b, a = string.find(name, ":microcontroller")
|
||||
local _, a = string.find(name, ":microcontroller")
|
||||
if a == nil then return nil end
|
||||
a = a + 1
|
||||
|
||||
|
Reference in New Issue
Block a user