["type"] = "compiled", |
["version"] = "1.0" |
["logic"] = {} |
["Test"]=LibLogic.Test |
} |
Compile_Local(logic,compiledLogic.logic) |
for i,val in ipairs(compiledlogic.logic) do -- just update the jump addresses |
if val[1] == 2 or val[1] == 3 then |
val[3] = val[3] + i |
end |
end |
return compiledLogic |
end |
|
-- for faster comparison: |
-- types: |
-- 0 value |
-- 1 function |
-- 2 and |
-- 3 or |
|
function LibLogic:Test(compiledLogic,arguments) |
local stack = {} |
local head = nil |
local operator = nil |
local running = true |
local pointer = 1 |
local last = # compiledLogic.logic |
local logic = compiledLogic.logic |
local current = nil |
local currtype = nil |
while running do |
current = logic[pointer] |
currtype = current[1] |
|
if currtype == 1 then -- function case, considered to be the most frequent |
if operator == 2 then -- doing and operations |
if not current[2](arguments) then -- if we are false |
while head and head[1]==2 do -- now we drop all and's until the first or or the end of the stack |
pointer = operator[3] -- jump to address |
head = table_remove(stack) |
end |
end |
else |
if operator == 3 then -- doing or operations |
if current[2](arguments) then -- if true, or is true |
while head and head[1]==3 do |
pointer = operator[3] |
head = table_remove(stack) |
end |
end |
else |
if not head then -- no operator loaded, just a single function |
return current[2](arguments) --RETURN ends function |
end |
end |
end |
else -- doing and |
if currtype == 2 or currtype == 3 then |
table_insert(stack,head) |
head = current |
operator = currtype |
else |
if currtype == 0 then |
return current[2] -- no need to do more for now |
end |
|
end |
end |
end |
|
|
|