View Single Post
Old 11-11-2019, 07:35 AM   #605
Human being with feelings
Lokasenna's Avatar
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,441

Originally Posted by woodslanding View Post
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:

if self:containsPoint(state.mouse.x, state.mouse.y) then

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.

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:
func = function(self, a, b, c) Msg(, a, b, c) end,
params = {"a", "b", "c"}
Lokasenna is online now   Reply With Quote