Is it either possible to get the size of a function in bytes to see if it matches another function similar to C++ sizeof operator, or evaluate two functions some other way to see if they are both equal without actually knowing what the function/s are? Example:
local function equals(func1, func2)
-- check them and return true if equal
end
If this is not possible just say and that will satisfy my answer! Thank you!
EDIT: The body of one function is what I need to check to see if it is the same as another function's body. The reference in memory will be different so I cannot use "==" but the function's reference name can be different.
Using
==
for functions only checks if they reference to the same function, which is not what you expected.This task is rather difficult, if not impossible at all. For really simple cases, here's an idea:
f
andg
are two function that are equal by your definition. Assuming the file ist.lua
, run:The output is:
As you can see, the two functions have the same instructions in the virtual machine.