lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Nick Trout wrote: 
> > ok = Button()
> > ok.onClick.add( exit )
> Just add a closure as a handler:
>  ok.onClick.add( function() app:exit() end )
> And if you need to bind any parameters you just put them in your
> closure?
>  ok.onClick.add( function() local s=0 app:exit(s) end )

yes, of course, I know there are other ways of doing the same thing, but
simply using app:exit was in my opinion 'cleaner'.

ok.onClick.add( app.exit, app )

still looks much more attractive to me.

app:connect( 'exit', ok.onClick )

would be an alternative...

> Or, instead of adding a function handler couldn?t you replace the
> default onClick function?
>  ok.onClick = function() exit() end
> or
>  ok.onClick = function() app:exit() end

yes, you can, but the idea was that onClick is a signal (or an event in c#
notation) and you can bind any number of slots (or eventHandlers) to it
dynamically. When the signal is triggered:


the list of bound methods is travelled and each one is called with something
like this:

obj:method( ok, ... )

or when obj is nil, just:

method( ok, ... )

Ignacio Castaño

Yahoo! Messenger
Nueva versión: Webcam, voz, y mucho más ¡Gratis! 
Descárgalo ya desde