-
Notifications
You must be signed in to change notification settings - Fork 2
Callbacks Tutorial
A callback is a function called when some event happens. An example might be an onClick callback of a clickable object. By using callbacks, there is no need to constantly poll for events, as code is automatically executed after the initial setup.
There are a couple of types of callbacks, and the way they are defined and used is different accordingly.
These are the most commonly used callbacks. They are specific to an instance, and are called when something happens to the instance. You define an instance callback like this:
function instance:callback( ... ) -- note the colon notation. `self` will be passed into instance callbacks
...
endThese are used for libraries and tasks that aren't specific to an instance. Simply put, they're plain old functions, and have to be registered by the thing that uses them. An example would be this:
local function callback( ... )
...
end
something.register( callback )An actual example of this is with Application:registerResourceLoader:
local function loader( content )
-- do stuff
end
application:registerResourceLoader( "type.x", loader )- Exception
- DynamicValueException
- ExpressionException
- IncorrectConstructorException
- IncorrectParameterException
- ParserException
- ResourceLoadException
- ThreadRuntimeException