Closures

comparefunctions

Compares two function values by their function identity.

Syntax

comparefunctions(func1: function, func2: function): boolean
Aliases comparefunction

Arguments

NameTypeDescription
func1functionFirst function value to convert with function identity.
func2functionSecond function value to convert with function identity.

Returns

NameTypeDescription
equalbooleantrue when both function values resolve to the same function identity; otherwise false.

Description

Compares two function values by their function identity. Both arguments must be functions. The function returns the boolean result of function identity(L, 1) == function identity(L, 2). It does not compare function bytecode, source, behavior, hashes, upvalues, or newcclosure mappings. comparefunction is an alias for the same function.

Call it with 2 parameter(s): func1, func2. The argument table explains which values are required and which ones only refine the behavior.

It returns equal (boolean). Use the returns table to separate successful values from nil results and recoverable errors.

Example

Compare two functions by their function identity.

local function sample()
    return "ok"
end

local same = comparefunctions(sample, sample)
print(same)