i am using lua oop to program, and i wanna pass an object as the parameter of callback functions to know which object pushed this event, but passed object lost its metatable in callback function, i can only access its data like o.text, no o:getText()
i am trying to use love.event instead of rewriting a new event system, so i have to write an own event sys?
table in love.event.push will lose metatable
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Party member
- Posts: 515
- Joined: Wed Oct 05, 2016 11:53 am
Re: table in love.event.push will lose metatable
Can you share some code, to illustrate the problem you are having? The part about losing the metatable in the process sounds odd.
Do remember that the colon(:) syntax is just syntactical sugar:
Do remember that the colon(:) syntax is just syntactical sugar:
Code: Select all
myObject:myFunction(arg1)
-- is the same as
myObject.myFunction(myObject,arg1)
function myObject:myFunction ( arg1 ) -- "self" is inferred
-- ...function body goes here
end
-- is the same as
function myObject.myFunction ( self, arg1 ) -- "self" is just convention here, if you're passing along objects
-- ...function body goes here
end
Re: table in love.event.push will lose metatable
MrFariator wrote: ↑Tue Nov 28, 2023 10:44 pm Can you share some code, to illustrate the problem you are having? The part about losing the metatable in the process sounds odd.
Code: Select all
local o = Human()
love.graphics.print(o:getName()) -- fine
love.event.push('MOVED', o)
-- or a wrapped method o:push('MOVED')
function handleMoved(e)
if e:getName() -- error
if e.name -- fine
end
I think i have to write an own event.push to pass a true reference.
- zorg
- Party member
- Posts: 3444
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: table in love.event.push will lose metatable
you should not use löve's event mechanics like that; yes, you should implement your own.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 70 guests