Fixes derived classes callbacks issue / fixes #827 #835
+41
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.