Go to most recent revision |
Compare with Previous |
Blame |
View Log
    
-- New functions that supersede the ones in Utils.lua.
-- Needs to be in a separate file in case someone installs one of my plugins that contains an old copy of Utils.lua.
-- New versions of RemoveCallback() and DoCallbacks() that tolerate removing an event handler from within an event handler:
function _G.RemoveCallback(object, event, callback)
    if (callback == nil) then
        return;
    end
    local handlers = object[event];
    if (handlers == callback) then
        object[event] = nil;
    elseif (type(handlers) == "table") then
        local f, i;
        repeat
            i, f = next(handlers, i);
            if (f == callback) then
                handlers[i] = nil;
            end
        until (i == nil);
    end
end
function _G.DoCallbacks(object, event, args)
    local handlers = object[event];
    if (type(handlers) == "function") then
        handlers(object, args);
    elseif (type(handlers) == "table") then
        if (next(handlers) == nil) then
            -- If all handlers have been removed, remove the table.
            object[event] = nil;
        else
            local f, i;
            repeat
                i, f = next(handlers, i);
                if (type(f) == "function") then
                    f(object, args);
                end
            until (i == nil);
        end
    end
end
     
Go to most recent revision |
Compare with Previous |
Blame
   
  			
			All times are GMT -5. The time now is 05:45 AM.