author | Mikael Berthe <mikael@lilotux.net> |
Thu, 15 Apr 2010 20:56:25 +0200 | |
changeset 21 | bc5d611e6d6f |
parent 20 | mcbot/cmds/misc.lua@d6c602aaa231 |
child 35 | 1fba2631c743 |
permissions | -rw-r--r-- |
16
064a50911e05
Update command infrastructure
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
1 |
|
064a50911e05
Update command infrastructure
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
2 |
local help = { ["desc"] = "Display the available commands" } |
21 | 3 |
|
16
064a50911e05
Update command infrastructure
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
4 |
function help.cmd (args) |
21 | 5 |
local r = "" |
6 |
||
7 |
local function pairsByKeys (t, f) |
|
8 |
local a = {} |
|
9 |
for n in pairs(t) do table.insert(a, n) end |
|
10 |
table.sort(a, f) |
|
11 |
local i = 0 -- iterator variable |
|
12 |
local iter = function () -- iterator function |
|
13 |
i = i + 1 |
|
14 |
if a[i] == nil then return nil |
|
15 |
else return a[i], t[a[i]] |
|
16 |
end |
|
17 |
end |
|
18 |
return iter |
|
19 |
end |
|
20 |
||
21 |
for name, obj in pairsByKeys(mcbot_get_command_list()) do |
|
22 |
if not obj.hidden then |
|
23 |
r = r .. string.format("%s\t%s\n", name, obj.desc or "") |
|
24 |
end |
|
25 |
end |
|
26 |
||
27 |
r = r:gsub("\n+$", "") |
|
28 |
return r |
|
16
064a50911e05
Update command infrastructure
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
29 |
end |
064a50911e05
Update command infrastructure
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
30 |
|
064a50911e05
Update command infrastructure
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
31 |
mcbot_register_command("help", help) |