Returns true when two closures are equivalent, meaning they run the same bytecode with the same captured state, even if they are distinct objects that == reports as unequal.

Parameters

function
required
The first closure.
function
required
The second closure.

Returns

boolean
true if the two closures are equivalent.

Behavior

Equivalence is decided on what the closures actually are, not on identity:
  • Both must be the same kind: both C closures, or both Luau closures.
  • C closures match when they share the same native function and the same upvalue values.
  • Luau closures match when they share the same proto and the same upvalue values.
This is what makes it useful after clonefunction: a clone is ~= to its source under ==, but comparefunctions confirms they are still the same function.

Example

Errors