Fix a bug in long conditions

This commit is contained in:
Jeija 2012-08-08 19:40:39 +02:00
parent da6cccf332
commit 0ee661d25d

@ -189,23 +189,26 @@ function yc_command_if_parsecondition(cond, L)
cond = string.gsub(cond, "!0", "1") cond = string.gsub(cond, "!0", "1")
cond = string.gsub(cond, "!1", "0") cond = string.gsub(cond, "!1", "0")
print(cond)
local i = 2 local i = 2
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)
local b = tonumber(cond:sub(i-1, i-1)) local b = tonumber(cond:sub(i-1, i-1))
local a = tonumber(cond:sub(i+1, i+1)) local a = tonumber(cond:sub(i+1, i+1))
if a == nil then break end if a == "" then print ("ERROR") break end
if s == "=" then if s == "=" then
buf = (a == b) print(b.."="..a.."?")
if buf == true then buf = "1" end if a == b then buf = "1" end
if buf == false 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)
i = 1 i = 1
l = string.len(cond) l = string.len(cond)
end end
i = i + 1 i = i + 1
end end
print(cond)
local i = 2 local i = 2
local l = string.len(cond) local l = string.len(cond)
@ -213,7 +216,7 @@ function yc_command_if_parsecondition(cond, L)
local s = cond:sub(i,i) local s = cond:sub(i,i)
local b = tonumber(cond:sub(i-1, i-1)) local b = tonumber(cond:sub(i-1, i-1))
local a = tonumber(cond:sub(i+1, i+1)) local a = tonumber(cond:sub(i+1, i+1))
if a == nil then break end if a == "" then break end
if s == "&" then if s == "&" then
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
@ -240,6 +243,7 @@ function yc_command_if_parsecondition(cond, L)
end end
i = i + 1 i = i + 1
end end
print(cond)
return cond return cond
end end