getfunctionhash
Returns a hash of the function's bytecode.
Syntax
getfunctionhash(func: function) -> stringParameters
| Parameter | Type | Description |
|---|---|---|
func | function | The function to hash |
Returns
| Type | Description |
|---|---|
string | A 96-character hexadecimal SHA-384 digest |
Description
getfunctionhash computes a SHA-384 digest over a Luau closure's instructions and constants. It throws for C closures, which have no Luau bytecode to hash.
Example
local function isSha384Hex(hash)
return #hash == 96 and hash:match("^[0-9a-fA-F]+$") ~= nil
end
local function first()
return "constant"
end
local function second()
return "different constant"
end
local firstHash = getfunctionhash(first)
local secondHash = getfunctionhash(second)
print(isSha384Hex(firstHash)) -- true
print(firstHash == secondHash) -- falseNotes
- Only works with Luau closures; C closures throw an error
- Slight changes in function bytecode will alter the returned hash