From 37eacc3a41cd2f8ddc13fb1e3d34678d65e23073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrique=20Garc=C3=ADa=20Cota?= Date: Mon, 30 Jan 2012 00:07:12 +0100 Subject: [PATCH] fixed an edge case that I can not reproduce with tests --- beholder.lua | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/beholder.lua b/beholder.lua index f48d073..09a46ed 100644 --- a/beholder.lua +++ b/beholder.lua @@ -11,6 +11,14 @@ local function copy(t) return c end +local function hash2array(t) + local arr, i = {}, 0 + for _,v in pairs(t) do + i = i+1 + arr[i] = v + end + return arr, i +end -- private Node class local nodesById = nil @@ -43,12 +51,12 @@ local function findOrCreateDescendantNode(self, keys) end local function invokeNodeCallbacks(self, params) - local counter = 0 - for _,callback in pairs(self.callbacks) do - callback(unpack(params)) - counter = counter + 1 + -- copy the hash into an array, for safety (self-erasures) + local callbacks, count = hash2array(self.callbacks) + for i=1,#callbacks do + callbacks[i](unpack(params)) end - return counter + return count end local function invokeAllNodeCallbacksInSubTree(self, params)