FunctionDispatcher = {}

FunctionDispatcher.functions = {}

FunctionDispatcher.AddFunction = function(fn, ...)
    local parameters = {...}
    local prepared_fun = {}
    local tag = table.getn(FunctionDispatcher.functions) + 1
    prepared_fun.fn = fn
    prepared_fun.parameters = parameters
    table.insert(FunctionDispatcher.functions, tag, prepared_fun)
    return tag
end

FunctionDispatcher.Call = function(tag, once)
    local prepared_fun = FunctionDispatcher.functions[tag]
    if prepared_fun ~= nil then
        pcall(prepared_fun.fn, unpack(prepared_fun.parameters))
        --prepared_fun.fn(unpack(prepared_fun.parameters))
        if once then
            FunctionDispatcher.functions[tag].fn = function() end
        end
    end
end

FunctionDispatcher.Remove = function(tag)
    FunctionDispatcher.functions[tag].fn = function() end
end

