hope you are all doing well
I have this issue and I don't know if what I am trying to do is possible in lua.
I have a table which has a function in it. Now I am passing this table from one class to another.
Is it possible to execute the function on the parent?Some code for you to see:
Menu.lua:
...
local mybtn = ButtonTP9UDDT.new({
scalexup=1, scalexdown=1.2,
audio=self:selectionSfxM(), -- this is the function
}, 1)
... |
ButtonTP9UDDT.lua:
...
-- if self.params.audio then pcall(self.params.audio) end
-- if self.params.audio then self:getParent():getfenv(self.params.audio) end
if self.params.audio then
local fun = self.params.audio
self:getParent():fun()
-- self.params.audio()
end
... |
self.params.audio holds the function from the table (checked with type(self.params.audio)).
As you can see, I have tried a couple of things to no avail
Is it possible to call a function in a table on the parent?
Thank you for your time
PS: I can do
if self.params.audio then self:getParent():selectionSfxM() end |
but I would like to pass the name of the function in a table, that would be more convenient.
Comments
to pass function as argument:
audio=self.selectionSfxM
Likes: MoKaLux
what is now working code:
class1:
Viva Gideros!
how does it fit in this? self.params.fun(self:getParent())
EDIT: now with the addition below from hgy29 I think we have all available possibilities
Likes: MoKaLux
Likes: MoKaLux