Syntax
getcallbackvalue(instance: Instance, property: string): function | nilgetcallbackmemberArguments
| Name | Type | Description |
|---|---|---|
instance | Instance | Instance object whose callback property should be inspected. Invalid Instance values raise an argument error. |
property | string | Property name to resolve with Roblox property metadata. Only LUA_CALLBACK properties can return a function. |
Returns
| Name | Type | Description |
|---|---|---|
callback | function | nil | Lua function stored by the callback property, or nil when the function cannot resolve a readable function. |
Description
Reads a Lua callback function stored in a callback property on an Instance. The first argument must be Instance object and the second argument must be a string property name. The instance reference must be valid. The property name is resolved with Roblox property metadata and must refer to a property whose type is LUA_CALLBACK. If the property descriptor is missing, the property is not LUA_CALLBACK, the callback field offset is missing, no callback is stored, the LiveLuaRef is missing, the callback belongs to a different Lua global state, or the referenced value is not a function, the function returns nil. It also checks the async callback field fallback when the first callback slot has no callback. The function does not update the property.
Call it with 2 parameter(s): instance, property. The argument table explains which values are required and which ones only refine the behavior.
It returns callback (function | nil). Use the returns table to separate successful values from nil results and recoverable errors.
Example
Read the callback function stored in a callback property such as BindableFunction.OnInvoke.
local bindable = Instance.new("BindableFunction")
bindable.OnInvoke = function(value)
return value * 2
end
local callback = getcallbackvalue(bindable, "OnInvoke")
if callback then
print(callback(21))
end