diff --git a/concord/world.lua b/concord/world.lua index 7008da4..7b31a6e 100644 --- a/concord/world.lua +++ b/concord/world.lua @@ -52,6 +52,8 @@ function World.new() __systemLookup = {}, __isWorld = true, + + __ignoreEmits = false }, World.__mt) -- Optimization: We deep copy the World class into our instance of a world. @@ -320,7 +322,14 @@ function World:emit(functionName, ...) self.__emitSDepth = self.__emitSDepth + 1 - local listeners = self.__events[functionName] + local listeners = self.__events[functionName] + + if not self.__ignoreEmits and Type.isCallable(self.beforeEmit) then + self.__ignoreEmits = true + local preventDefaults = self:beforeEmit(functionName, listeners, ...) + self.__ignoreEmits = false + if preventDefaults then return end + end if listeners then for i = 1, #listeners do @@ -336,6 +345,12 @@ function World:emit(functionName, ...) end end + if not self.__ignoreEmits and Type.isCallable(self.afterEmit) then + self.__ignoreEmits = true + self:afterEmit(functionName, listeners, ...) + self.__ignoreEmits = false + end + self.__emitSDepth = self.__emitSDepth - 1 return self