Skip to content

Lua connect and disconnect event handler bug #827

@zygzagZ

Description

@zygzagZ

Hello.
There is a bug that sometimes makes handlers for LocalPlayer trigger for Creature events etc.
I.e. in a (not so) special case any handler bound to a derived class can be triggered by base class event.

Steps to reproduce:
bind lua handler to Creature.onPositionChange that does nothing
bind lua handler to LocalPlayer.onPositionChange(player) that prints player:getName()

Expected behaviour:
The only prints in console are local player's name.

Actual behaviour:
When any creature moves, it's name appears in console

The reason behind this is that connect function searches for list of signal handlers in any of base classes and if it hasn't found any, it creates one in current class.
The call to bind handler to LocalPlayer finds one in Creature (that is base class of LocalPlayer) and inserts event handler there, so calls by Creature events are also triggering LocalPlayer handlers.

The fix would be using rawget and rawset to always add trigger handler in current object, and in signalcall to iterate over metatables in order to trigger handlers of all base classes.

Please confirm that this is actually a bug, and not a feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions