mirror of
https://github.com/minetest-mods/mesecons.git
synced 2024-09-12 07:58:32 +02:00
Bugfixes for microcontroller and use #addr instead of <addr>
This commit is contained in:
parent
2d94a08d2e
commit
89edd2ce63
@ -154,15 +154,15 @@ function parse_get_params(code, starti)
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function yc_parse_get_eeprom_params(code, starti)
|
function yc_parse_get_eeprom_param(cond, starti)
|
||||||
i = starti
|
i = starti
|
||||||
s = nil
|
s = nil
|
||||||
local params = {}
|
local addr
|
||||||
while s ~= "" do
|
while s ~= "" do
|
||||||
s = string.sub(code, i, i)
|
s = string.sub(cond, i, i)
|
||||||
if s == ">" then
|
if string.find("0123456789", s) == nil or s == "" then
|
||||||
table.insert(params, string.sub(code, starti, i-1)) -- i: ) i+1 after )
|
addr = string.sub(cond, starti, i-1) -- i: last number i+1 after last number
|
||||||
return params, i + 1
|
return addr, i
|
||||||
end
|
end
|
||||||
if s == "," then return nil, nil end
|
if s == "," then return nil, nil end
|
||||||
i = i + 1
|
i = i + 1
|
||||||
@ -242,16 +242,13 @@ function yc_command_if_parsecondition(cond, L, eeprom)
|
|||||||
cond = string.gsub(cond, "C", tonumber(L.c and 1 or 0))
|
cond = string.gsub(cond, "C", tonumber(L.c and 1 or 0))
|
||||||
cond = string.gsub(cond, "D", tonumber(L.d and 1 or 0))
|
cond = string.gsub(cond, "D", tonumber(L.d and 1 or 0))
|
||||||
|
|
||||||
cond = string.gsub(cond, "!0", "1")
|
|
||||||
cond = string.gsub(cond, "!1", "0")
|
|
||||||
|
|
||||||
local i = 1
|
local i = 1
|
||||||
local l = string.len(cond)
|
local l = string.len(cond)
|
||||||
while i<=l do
|
while i<=l do
|
||||||
local s = cond:sub(i,i)
|
local s = cond:sub(i,i)
|
||||||
if s == "<" then
|
if s == "#" then
|
||||||
params, endi = yc_parse_get_eeprom_params(cond, i+1)
|
addr, endi = yc_parse_get_eeprom_param(cond, i+1)
|
||||||
buf = yc_eeprom_read(tonumber(params[1]), eeprom)
|
buf = yc_eeprom_read(tonumber(addr), eeprom)
|
||||||
if buf == nil then return nil end
|
if buf == nil then return nil end
|
||||||
local call = cond:sub(i, endi-1)
|
local call = cond:sub(i, endi-1)
|
||||||
cond = string.gsub(cond, call, buf)
|
cond = string.gsub(cond, call, buf)
|
||||||
@ -261,6 +258,9 @@ function yc_command_if_parsecondition(cond, L, eeprom)
|
|||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
cond = string.gsub(cond, "!0", "1")
|
||||||
|
cond = string.gsub(cond, "!1", "0")
|
||||||
|
|
||||||
local i = 2
|
local i = 2
|
||||||
local l = string.len(cond)
|
local l = string.len(cond)
|
||||||
while i<=l do
|
while i<=l do
|
||||||
@ -269,6 +269,7 @@ function yc_command_if_parsecondition(cond, L, eeprom)
|
|||||||
local a = tonumber(cond:sub(i+1, i+1))
|
local a = tonumber(cond:sub(i+1, i+1))
|
||||||
if cond:sub(i+1, i+1) == nil then break end
|
if cond:sub(i+1, i+1) == nil then break end
|
||||||
if s == "=" then
|
if s == "=" then
|
||||||
|
if a==nil then return nil end
|
||||||
if a == b then buf = "1" end
|
if a == b then buf = "1" end
|
||||||
if a ~= b then buf = "0" end
|
if a ~= b then buf = "0" end
|
||||||
cond = string.gsub(cond, b..s..a, buf)
|
cond = string.gsub(cond, b..s..a, buf)
|
||||||
@ -286,6 +287,7 @@ function yc_command_if_parsecondition(cond, L, eeprom)
|
|||||||
local a = tonumber(cond:sub(i+1, i+1))
|
local a = tonumber(cond:sub(i+1, i+1))
|
||||||
if cond:sub(i+1, i+1) == nil then break end
|
if cond:sub(i+1, i+1) == nil then break end
|
||||||
if s == "&" then
|
if s == "&" then
|
||||||
|
if a==nil then return nil end
|
||||||
local buf = ((a==1) and (b==1))
|
local buf = ((a==1) and (b==1))
|
||||||
if buf == true then buf = "1" end
|
if buf == true then buf = "1" end
|
||||||
if buf == false then buf = "0" end
|
if buf == false then buf = "0" end
|
||||||
@ -294,6 +296,7 @@ function yc_command_if_parsecondition(cond, L, eeprom)
|
|||||||
l = string.len(cond)
|
l = string.len(cond)
|
||||||
end
|
end
|
||||||
if s == "|" then
|
if s == "|" then
|
||||||
|
if a==nil then return nil end
|
||||||
local buf = ((a == 1) or (b == 1))
|
local buf = ((a == 1) or (b == 1))
|
||||||
if buf == true then buf = "1" end
|
if buf == true then buf = "1" end
|
||||||
if buf == false then buf = "0" end
|
if buf == false then buf = "0" end
|
||||||
@ -302,6 +305,7 @@ function yc_command_if_parsecondition(cond, L, eeprom)
|
|||||||
l = string.len(cond)
|
l = string.len(cond)
|
||||||
end
|
end
|
||||||
if s == "~" then
|
if s == "~" then
|
||||||
|
if a==nil then return nil end
|
||||||
local buf = (((a == 1) or (b == 1)) and not((a==1) and (b==1)))
|
local buf = (((a == 1) or (b == 1)) and not((a==1) and (b==1)))
|
||||||
if buf == true then buf = "1" end
|
if buf == true then buf = "1" end
|
||||||
if buf == false then buf = "0" end
|
if buf == false then buf = "0" end
|
||||||
@ -315,8 +319,8 @@ function yc_command_if_parsecondition(cond, L, eeprom)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function yc_eeprom_read(number, eeprom)
|
function yc_eeprom_read(number, eeprom)
|
||||||
if params == nil then return nil, nil end
|
if number == nil then return nil, nil end
|
||||||
value = eeprom:sub(params[1], number)
|
value = eeprom:sub(number, number)
|
||||||
if value == nil then return nil, nil end
|
if value == nil then return nil, nil end
|
||||||
return value, endi
|
return value, endi
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user