[CSM] Add client-sided chat commands (#5092)
[oweals/minetest.git] / builtin / common / chatcommands.lua
1 -- Minetest: builtin/common/chatcommands.lua
2
3 core.registered_chatcommands = {}
4
5 function core.register_chatcommand(cmd, def)
6         def = def or {}
7         def.params = def.params or ""
8         def.description = def.description or ""
9         def.privs = def.privs or {}
10         def.mod_origin = core.get_current_modname() or "??"
11         core.registered_chatcommands[cmd] = def
12 end
13
14 function core.unregister_chatcommand(name)
15         if core.registered_chatcommands[name] then
16                 core.registered_chatcommands[name] = nil
17         else
18                 core.log("warning", "Not unregistering chatcommand " ..name..
19                         " because it doesn't exist.")
20         end
21 end
22
23 function core.override_chatcommand(name, redefinition)
24         local chatcommand = core.registered_chatcommands[name]
25         assert(chatcommand, "Attempt to override non-existent chatcommand "..name)
26         for k, v in pairs(redefinition) do
27                 rawset(chatcommand, k, v)
28         end
29         core.registered_chatcommands[name] = chatcommand
30 end