Parsing anonymous function as parameter
Posted: Fri Dec 26, 2014 4:37 am
So I have a problem with a function not being called after parsing it into a function.
Essentially I am making a Simple button interface for my project, and thought it'd be simple enough to give the button an action as an anonymous function specified at creation.
So essentially I have a button object, and the main love interface; in which I create the button, with its desired action, and on mouse click call button.action and it should call the function. Except it doesn't seem to work!
To test this I made a generic global variable, glob, and I passed a the function "function () glob = glob + 1".
The button class looks something like:
Button = {}
Function button(button-action)
Local self
...
Local Action = button-action
...
Function self.get-button-action() return action end
Return self
End
And I call something like
B = button.new(function () glob = glob + 1 end )
And on mouse press:
B.get-button-action()
However global does not change after that!
Is there something obvious I am missing or what would the problem be?
Unfortunately I'm already on holidays and away from my PC and I am typing this on my phone, however the question is pestering me and I can't not think about it
Sorry if there are some typos or whatever, and I wish you all a merry end of year celebration of your choice!
Thanks guys!
Essentially I am making a Simple button interface for my project, and thought it'd be simple enough to give the button an action as an anonymous function specified at creation.
So essentially I have a button object, and the main love interface; in which I create the button, with its desired action, and on mouse click call button.action and it should call the function. Except it doesn't seem to work!
To test this I made a generic global variable, glob, and I passed a the function "function () glob = glob + 1".
The button class looks something like:
Button = {}
Function button(button-action)
Local self
...
Local Action = button-action
...
Function self.get-button-action() return action end
Return self
End
And I call something like
B = button.new(function () glob = glob + 1 end )
And on mouse press:
B.get-button-action()
However global does not change after that!
Is there something obvious I am missing or what would the problem be?
Unfortunately I'm already on holidays and away from my PC and I am typing this on my phone, however the question is pestering me and I can't not think about it
Sorry if there are some typos or whatever, and I wish you all a merry end of year celebration of your choice!
Thanks guys!