You are here: Lua Scripting Resources eGuide > Lua Scripting API Reference Guide > Event Handling

8.0

Event Handling

Script applications respond to external stimuli by implementing event handlers. All the event handlers are grouped in the “on” module.

Example

For example, the application script implements on.paint(gc) to be notified when it is time to redraw its window. on.paint is passed a graphics context that it can use to call drawing routines on its window.

Listing 8.1: Event Handler Example

function on.paint(gc) 
  gc:drawLine(...)
  :

end

Simplified Open Document Scenario

There are many scenarios that can be discussed in detail. All specifics about the behavior of particular events are discussed as part of the event description.

However the open document scenario will be discussed here to visualize options and the order of the events received. In reality there might be many more events involved due to painting the script in different contexts (page sorter).

Based on the API level of the script, either the routine on.construction or on.create is called. The idea of on.construction is first to separate the definition of variables classes (done in main) from constructing the app; secondly to separate the layout from construction (on.resize()). The main issue of on.create() is the missing ability to invalidate (subsection 14.7.2) and the mix of creation and layout. The latter might be impacted in some cases due to the missing capability of requesting to invalidate the screen. Another option is the call to on.restore(), which is only done when the script is saved and provided a state table (see section 8.41). The following figure shows this visually.

In addition, it is also important to understand that a script may not have a size before the on.resize() event is received. Calling width or height of the platform window (subsection 14.7.1) before on.resize() may return 0.

Figure 8.1: Open Document Sequence Chart

Related Topics

activate

arrowDown

arrowKey

arrowLeft

arrowRight

arrowUp

charIn

backspaceKey

backTabKey

clearKey

construction

contextMenu

copy

create

createMathBox

cut

deactivate

deleteKey

destroy

enterKey

escapeKey

getFocus

getSymbolList

grabDown

grabUp

help

keyboardDown

keyboardUp

loseFocus

mouseDown

mouseMove

mouseUp

paint

paste

propertiesChanged

resize

restore

returnKey

rightMouseDown

rightMouseUp

save

tabKey

timer

varchange