getfunctionhash

Returns a hash of the function's bytecode.

Syntax

getfunctionhash(func: function) -> string

Parameters

ParameterTypeDescription
funcfunctionThe function to hash

Returns

TypeDescription
stringA 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) -- false

Notes

  • Only works with Luau closures; C closures throw an error
  • Slight changes in function bytecode will alter the returned hash