Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes derived classes callbacks issue / fixes #827 #835

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zygzagZ
Copy link
Contributor

@zygzagZ zygzagZ commented Apr 22, 2017

Fixes #827
The problem:
Each class in lua has a list of callbacks connected to given event and a parent class.
"signalcall" function calls a list of callbacks connected using "connect" function to a given object.
Let's say we have class A, A's event and class B derived from class A
If we connect a callback to A.event, it runs correctly.
Then we add a callback to B.event.
What should happen: the B callback runs only on B's events
What actually happens: the B callbacks runs on both A's and B's events
Why: "connect" checks whether B already has a list of callbacks to append new one. It does this incorrectly and gets A's list instead. Then it appends new callback to this list.
This has to do with metatables handling in lua
The fix: I have implemented a "hasValue" function checking whether some value in object is really this object's value or rather metatable's one.
When adding a callback, it checks whether the list exists for given object using mentioned function, and if it does not, creates the list, appends connected callback and also a function that bubbles the event up to base class.
It is necessary, because if there wasn't such function then creating new list of callbacks would make callbacks to any of base classes not reachable from this and derived classes.

@zygzagZ zygzagZ changed the title Fixes derived classes callbacks issue Fixes derived classes callbacks issue / fixes #827 Apr 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lua connect and disconnect event handler bug
1 participant