diff --git a/libs/core/codal.cpp b/libs/core/codal.cpp index b1d3dc2b9df..d6e43c6ad0c 100644 --- a/libs/core/codal.cpp +++ b/libs/core/codal.cpp @@ -102,6 +102,13 @@ void registerWithDal(int id, int event, Action a, int flags) { registerGCPtr(a); } +void unregisterWithDal(int id, int event, Action a) { + uBit.messageBus.ignore(id, event, dispatchForeground, a); + decr(a); + unregisterGCPtr(a); +} + + void fiberDone(void *a) { decr((Action)a); unregisterGCPtr((Action)a); diff --git a/libs/core/control.cpp b/libs/core/control.cpp index 031c37e7b92..a62c59ba848 100644 --- a/libs/core/control.cpp +++ b/libs/core/control.cpp @@ -2,6 +2,10 @@ extern uint32_t __StackTop; +namespace pxt { + void unregisterWithDal(int id, int event, Action a); +} + /** * How to create the event. */ @@ -312,6 +316,14 @@ namespace control { registerWithDal(src, value, handler, (int)flags); } + /** + * Removes an event handler binding. + */ + //% + void removeEventBinding(int src, int value, Action handler) { + unregisterWithDal(src, value, handler); + } + /** * Gets the value of the last event executed on the bus */