ReferenceClosures

getfunctionhash

Returns a hash that identifies a Luau function's code.

Syntax

getfunctionhash(func: function) -> string

Also available as

get_function_hash

Parameters

ParameterTypeDescription
funcfunctionA Luau function.

Returns

TypeDescription
stringA 96-character hexadecimal SHA-384 hash of the function's bytecode and constants.

Description

Two functions compiled from the same source get the same hash, even when they are different values or come from different scripts, and a change to the code or to any constant changes the hash. Upvalue values and the environment do not take part. Runtime field-access caches, method-call caches and table-constructor hints are excluded, so merely calling a function must not change its hash. Nested functions are hashed by their code rather than allocation addresses. Hashes are scoped to compatible compiler/engine versions; do not persist them as a universal identifier across upgrades.

Example

local a = loadstring("return function(x) return x + 1 end")()
local b = loadstring("return function(x) return x + 1 end")()
local c = loadstring("return function(x) return x + 2 end")()

print(getfunctionhash(a) == getfunctionhash(b))
print(getfunctionhash(a) == getfunctionhash(c))

Notes

These are Game executor contracts. Check build requirements and session lifetimes before using them.