AmericanNero
Seasoned veteran member
- Joined
- Oct 13, 2020
- RedCents
- 4,709¢
Using JIT conditional evaluation is highly convenient in Macros, but, how do we do it in Lua?
The MacroQuest INI command supports noparse. Fortunately we don't need to specify that when loading INI anymore. There is a simple load/save lib which will read the contents into a table, where you can then make edits, then save. Back to evaluating conditions.
Here is what I've cooked up. Any suggestions appreciated.
The MacroQuest INI command supports noparse. Fortunately we don't need to specify that when loading INI anymore. There is a simple load/save lib which will read the contents into a table, where you can then make edits, then save. Back to evaluating conditions.
Here is what I've cooked up. Any suggestions appreciated.
JavaScript:
--[[
Read the contents of an INI into a table, ex reference: pc.ACond.Cond1
[ACond]
; Cond takes a LUA expression
; Cond1 returns false. Cond2 returns true.
Cond1=mq.TLO.Me.Name ~= mq.TLO.Me.Name
Cond2=mq.TLO.Me.Name == mq.TLO.Me.Name
--]]
local function Eval_Cond(cond)
result=false
local test_cond = load('result=' .. cond)
test_cond()
return result
end
local Cond1="mq.TLO.Me.Name ~= mq.TLO.Me.Name"
local Cond2="mq.TLO.Me.Name == mq.TLO.Me.Name"
print (Eval_Cond(Cond1))
print (Eval_Cond(Cond2))


