Quote:
Originally Posted by woodslanding
Thanks! A lot of good information there about how arguments work.
I'm going to have to get my head around passing functions around. It's all new to me and makes my head spin a bit....
As an example, in 'working with images' I find:
Code:
if self:containsPoint(state.mouse.x, state.mouse.y) then
self.func(table.unpack(self.params))
self.params here refers to func's self, is that right? Am I right in thinking that func as an argument to the control should be the function we want it to execute when the button is pressed?
|
self is just an argument; in this case
self is the IButton. If you're used to something like Javascript's
this,
self isn't passed around the same way.
Quote:
I'm trying to imagine what syntax I would use to have the func parameter call an action that required the value of self.state as an argument... I've figured other ways to do that without func, (basically overriding the control's mouse methods with direct calls) but it seems like I'm missing the point. There is an easier way, correct?
|
I've just pushed an update for you.
. User functions for Button, Menubar, and the IButton example in the image script all receive
self as their first argument. i.e. when creating them you would use:
Code:
func = function(self, a, b, c) Msg(self.name, a, b, c) end,
params = {"a", "b", "c"}