Window.pumpmessages

From codeTank

Jump to: navigation, search

Contents

Description

window.pumpmessages is a vital function for the window implementation. When a window is created, it begins listening for events. Messages are delivered to the window, but are put in a queue. window.pumpmessages will take the next message on the queue, and call the appropriate event handler.

If no messages are in the queue, then window.pumpmessages will sit and wait for a message to be generated. Once a message is generated, it will call the appropriate event handler.

window.pumpmessages will always convert exactly one message into an event. If no messages exist, then it will wait for a message to be generated. If you want to perform extra processing instead of waiting around for a message, then use window.hasmessages to detect whether any messages exist, and only call window.pumpmessages if there are messages already in the queue.

Arguments

None.

Returns

None.

Example

wnd = window.create{
    onpaint = function(wnd, pnt)
            pnt:rectangle(math.random(0, wnd.width), math.random(0, wnd.height),
                math.random(0, 100), math.random(0, 100),
                false, rgb(0, math.random(255)))
        end,
    }

while window.getcount() > 0 do
    if (window.hasmessages()) then
        window.pumpmessages()
    else
        wnd:invalidate(false)
        syncframe(0.01)
    end
end

See Also

Personal tools