Comparison Functions
The Compare category provides comparison operations that mirror the functionality of comparison nodes.
Available Functions
Compare.string(a, b, operator)- Compares two stringsCompare.number(a, b, operator)- Compares two numbersCompare.boolean(a, b, operator)- Compares two booleansCompare.array(a, b, operator)- Compares two arraysCompare.object(a, b, operator)- Compares two objectsCompare.datetimeUnix(a, b, operator)- Compares Unix timestampsCompare.datetimeISO(a, b, operator)- Compares ISO 8601 datetime strings
Examples
String Comparison
local isEqual = Compare.string("Hello", "Hello", "==") -- Returns true
local isLess = Compare.string("Apple", "Banana", "<") -- Returns true
Number Comparison
local isGreater = Compare.number(10, 5, ">") -- Returns true
local isEqual = Compare.number(5.0, 5, "==") -- Returns true
Boolean Comparison
local isEqual = Compare.boolean(true, true, "==") -- Returns true
local isNotEqual = Compare.boolean(true, false, "!=") -- Returns true
Array Comparison
local arr1 = {1, 2, 3}
local arr2 = {1, 2, 3}
local isEqual = Compare.array(arr1, arr2, "==") -- Returns true
Object Comparison
local obj1 = {name = "John", age = 30}
local obj2 = {name = "John", age = 30}
local isEqual = Compare.object(obj1, obj2, "==") -- Returns true
DateTime Comparison
-- Unix timestamp comparison
local isNewer = Compare.datetimeUnix(1609459200, 1577836800, ">") -- Returns true
-- ISO 8601 comparison
local isNewer = Compare.datetimeISO("2021-01-01T00:00:00Z", "2020-01-01T00:00:00Z", ">") -- Returns true
Parameters
a- First value to compareb- Second value to compareoperator- Comparison operator:"=="- Equal"!="- Not equal"<"- Less than">"- Greater than"<="- Less than or equal">="- Greater than or equal
Return Values
All comparison functions return a boolean value indicating the result of the comparison.