Name
RunCallback -- push callback into event queue (V9.0)
Synopsis
RunCallback(func[, userdata])
Library
event

Function
This function adds the function specified by func to the event queue. The function will be run the next time Hollywood checks the event queue, i.e. when CheckEvent() or WaitEvent() gets called.

The optional userdata argument allows you to specify additional data that will be passed to your callback function whenever it is called. This is useful if you want to avoid working with global variables. Using the userdata argument you can easily pass data to your callback function. You can specify a value of any type in userdata. Numbers, strings, tables, and even functions can be passed as user data.

Your callback function will be called by Hollywood with a single parameter. The parameter is a message table which contains the following fields:

Action:
Will be always set to RunCallback. This field is a string!

UserData:
Will be set to what you have specified in the userdata argument when calling RunCallback(). Note that this field will only be there if you have actually passed a value in userdata when calling RunCallback().

Inputs
function
function to be added to the event queue
userdata
optional: user data to be passed to the function when running it
Example
RunCallback(Function(msg) NPrint(msg.userdata) EndFunction, "Hello 2!")
NPrint("Hello 1!")
Repeat
   WaitEvent
Forever
This will first print "Hello 1!" and then "Hello 2!" because the function that prints "Hello 2!" won't be called until Hollywood empties the event queue which happens on WaitEvent().

Show TOC