- Joined
- Mar 29, 2016
- Messages
- 688
Lua:
--[[ boolexproverride.lua v1.0.0 by AGD | https://www.hiveworkshop.com/threads/339629/
Description:
Overrides the native boolexpr functions Filter(), Not(), And(), and Or().
With the native functions, evaluating a nested boolexpr such as:
local nestedExpr = And(Or(Filter(funcA), Filter(funcB)), Or(Filter(funcC), Filter(funcD)))
local t = CreateTrigger()
TriggerAddCondition(t, nestedExpr)
TriggerEvaluate(t)
will have 7 boolexpr evaluations in total. Using these new overrides,
the 7 boolexpr evaluations will be replaced by 7 function calls + a
constant overhead of 1 boolexpr evaluation.
Aside from these overrides, this script additionally provides a function
for retrieving the corresponding function from a given boolexpr.
Requirements:
- None
]] --
--[[
API:
function FilterToFunc(filter_expr: boolexpr): function
- Returns the corresponding function for the given boolexpr
]] --
do
local expr_func = {}
local oldFilter = Filter
function Filter(filter_func)
local filter_expr = oldFilter(filter_func)
expr_func[filter_expr] = filter_func
return filter_expr
end
Condition = Filter
function Not(filter_expr)
return Filter(function()
return not expr_func[filter_expr]()
end)
end
function And(left_filter_expr, right_filter_expr)
return Filter(function()
return expr_func[left_filter_expr]() and expr_func[right_filter_expr]()
end)
end
function Or(left_filter_expr, right_filter_expr)
return Filter(function()
return expr_func[left_filter_expr]() or expr_func[right_filter_expr]()
end)
end
--- Returns the corresponding function for the given boolexpr
---@param filter_expr boolexpr
---@return function
function FilterToFunc(filter_expr)
return expr_func[filter_expr]
end
end
Last edited: