summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeija <norrepli@gmail.com>2012-08-08 15:09:05 +0200
committerJeija <norrepli@gmail.com>2012-08-08 15:09:05 +0200
commite3d2b07cd56b94d049c753d7f6f8c5d63ce9ac47 (patch)
treefb85984ec08b89aebfd36b8eedac2e9163b502ca
parentef740353ef798f40fef8b3b512ce0994637cc5c1 (diff)
downloadmesecons-e3d2b07cd56b94d049c753d7f6f8c5d63ce9ac47.tar
mesecons-e3d2b07cd56b94d049c753d7f6f8c5d63ce9ac47.tar.gz
mesecons-e3d2b07cd56b94d049c753d7f6f8c5d63ce9ac47.tar.bz2
mesecons-e3d2b07cd56b94d049c753d7f6f8c5d63ce9ac47.tar.xz
mesecons-e3d2b07cd56b94d049c753d7f6f8c5d63ce9ac47.zip
Important bugfix for if
-rw-r--r--mesecons_microcontroller/init.lua71
1 files changed, 38 insertions, 33 deletions
diff --git a/mesecons_microcontroller/init.lua b/mesecons_microcontroller/init.lua
index d594be5..a9c792d 100644
--- a/mesecons_microcontroller/init.lua
+++ b/mesecons_microcontroller/init.lua
@@ -159,6 +159,29 @@ end
function yc_command_if(code, starti, L)
local cond, endi = yc_command_if_getcondition(code, starti)
if cond == nil then return nil end
+
+ cond = yc_command_if_parsecondition(cond, L)
+
+ if cond == "0" then result = false
+ elseif cond == "1" then result = true
+ else result = nil end
+ return result, endi --endi from local cond, endi = yc_command_if_getcondition(code, starti)
+end
+
+function yc_command_if_getcondition(code, starti)
+ i = starti
+ s = nil
+ while s ~= "" do
+ s = string.sub(code, i, i)
+ if s == ")" then
+ return string.sub(code, starti, i-1), i + 1 -- i: (; i+1 after (;
+ end
+ i = i + 1
+ end
+ return nil, nil
+end
+
+function yc_command_if_parsecondition(cond, L)
cond = string.gsub(cond, "A", tostring(L.a and 1 or 0))
cond = string.gsub(cond, "B", tonumber(L.b and 1 or 0))
cond = string.gsub(cond, "C", tonumber(L.c and 1 or 0))
@@ -166,6 +189,20 @@ function yc_command_if(code, starti, L)
cond = string.gsub(cond, "!0", "1")
cond = string.gsub(cond, "!1", "0")
+ local i = 2
+ local l = string.len(cond)
+ while i<=l do
+ local s = cond:sub(i,i)
+ local b = tonumber(cond:sub(i-1, i-1))
+ local a = tonumber(cond:sub(i+1, i+1))
+ if a == nil then break end
+ if s == "=" then
+ cond = string.gsub(cond, b..s..a, tostring(a == b))
+ i = 1
+ l = string.len(cond)
+ end
+ i = i + 1
+ end
local i = 2
local l = string.len(cond)
@@ -200,39 +237,7 @@ function yc_command_if(code, starti, L)
end
i = i + 1
end
-
- local i = 2
- local l = string.len(cond)
- while i<=l do
- local s = cond:sub(i,i)
- local b = tonumber(cond:sub(i-1, i-1))
- local a = tonumber(cond:sub(i+1, i+1))
- if a == nil then break end
- if s == "=" then
- cond = string.gsub(cond, b..s..a, tostring(a == b))
- i = 1
- l = string.len(cond)
- end
- i = i + 1
- end
-
- if cond == "0" then result = false
- elseif cond == "1" then result = true
- else result = nil end
- return result, endi --endi from local cond, endi = yc_command_if_getcondition(code, starti)
-end
-
-function yc_command_if_getcondition(code, starti)
- i = starti
- s = nil
- while s ~= "" do
- s = string.sub(code, i, i)
- if s == ")" then
- return string.sub(code, starti, i-1), i + 1 -- i: (; i+1 after (;
- end
- i = i + 1
- end
- return nil, nil
+ return cond
end
function yc_get_port_rules(port)