Using == for functions only checks to see if they reference the same function, which you did not expect.
This task is rather difficult, if not impossible at all. For really simple cases, here is the idea:
function f(x) return x + 1 end local g = function(y) return y + 1 end
f and g are two functions that are equal to your definition. Assuming the t.lua file, run:
luac -l t.lua
Output:
main <t.lua:0,0> (4 instructions at 00000000003081c0) 0+ params, 2 slots, 1 upvalue, 1 local, 1 constant, 2 functions 1 [1] CLOSURE 0 0 ; 0000000000308330 2 [1] SETTABUP 0 -1 0 ; _ENV "f" 3 [2] CLOSURE 0 1 ; 0000000000308dc0 4 [2] RETURN 0 1 function <t.lua:1,1> (3 instructions at 0000000000308330) 1 param, 2 slots, 0 upvalues, 1 local, 1 constant, 0 functions 1 [1] ADD 1 0 -1 ; - 1 2 [1] RETURN 1 2 3 [1] RETURN 0 1 function <t.lua:2,2> (3 instructions at 0000000000308dc0) 1 param, 2 slots, 0 upvalues, 1 local, 1 constant, 0 functions 1 [2] ADD 1 0 -1 ; - 1 2 [2] RETURN 1 2 3 [2] RETURN 0 1
As you can see, both functions have the same instructions on the virtual machine.
source share