hookluatable
Intercepts missing-key lookups on a table.
Syntax
Signature
hookluatable(Table: table, Callback: function) -> ()Aliases
This function has no aliases.
Parameters
| Parameter | Type | Description |
|---|---|---|
Table | table | Table whose metatable will be replaced. |
Callback | function | Called as Callback(Key, Continue). Its first return value becomes the lookup result. |
Returns
| Type | Description |
|---|---|
() | None. |
Notes
Replaces Table's metatable with a new __index handler. Existing raw keys bypass the handler. For a missing key, Callback receives the key and a zero-argument continuation that raw-reads that key from Table. The previous metatable and __index handler are not preserved.
Example
Luau
local Values = {}
hookluatable(Values, function(Key, Continue)
if Key == "Answer" then return 42 end
return Continue()
end)
print(Values.Answer)