getfunctionhash
Returns the SHA-384 hex hash of a Luau function's bytecode.
function getfunctionhash(func: (...any) -> (...any)): stringSynopsis
How it works
Computes a hash (typically SHA-384SHA (hash family)Secure Hash Algorithm family: SHA-1 (160-bit, broken), SHA-256/SHA-384/SHA-512 (SHA-2 family, secure), SHA3-256 (Keccak-based). Used by crypt.hash() to produce fixed-size digests from arbitrary input data. or similar) of a function’s bytecodeBytecodeThe compiled binary representation of Luau source code. A sequence of 32-bit instructions (opcodes + operands) stored in a Proto's code[] array. Executed by the Luau VM interpreter. or internal representation. For Luau closures, the hash covers the
Proto bytecode, constants, and upvalueUpvalueA variable captured from an enclosing scope. When a function references a local variable from an outer function, that variable becomes an upvalue — stored in an UpVal struct that persists even after the outer function returns. count. For C closures, it hashes the C function pointer and upvalue contents.Integrity checking
Compare a function’s hash before and after a suspected hook to determine if it has been modified. If
getfunctionhash(fn) changes between checks, the function was hooked or replaced. Combine with restorefunction() to revert tampered functions.Usage
Verify a function has not been hooked
local baseline = getfunctionhash(MyModule.update)
"cc">-- Later, after potential tampering...
if getfunctionhash(MyModule.update) ~= baseline then
warn("MyModule.update has been modified!")
endParameters
func function The Luau function to hash. Must not be a C closure.
Returns
string A 96-character lowercase hex string representing the SHA-384 hash of the function's instructions and constants.
C closures unsupported
Calling getfunctionhash on a C closure (e.g. print, math.abs) throws an error citing "lua function expected".