mcbot/cmds/help.lua
author Mikael Berthe <mikael@lilotux.net>
Sun, 18 Apr 2010 23:42:12 +0200
changeset 35 1fba2631c743
parent 21 bc5d611e6d6f
permissions -rw-r--r--
Add command tvcal


local help = { ["desc"] = "Display the available commands" }

function help.cmd (args)
    local r = ""

    -- Function from PIL
    local function pairsByKeys (t, f)
        local a = {}
        for n in pairs(t) do table.insert(a, n) end
        table.sort(a, f)
        local i = 0      -- iterator variable
        local iter = function ()   -- iterator function
            i = i + 1
            if a[i] == nil then return nil
            else return a[i], t[a[i]]
            end
        end
        return iter
    end

    for name, obj in pairsByKeys(mcbot_get_command_list()) do
        if not obj.hidden then
            r = r .. string.format("%s\t%s\n", name, obj.desc or "")
        end
    end

    r = r:gsub("\n+$", "")
    return r
end

mcbot_register_command("help", help)