diff options
author | Elijah Duffy <enduffy2014@outlook.com> | 2017-01-20 10:49:20 -0800 |
---|---|---|
committer | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-01-20 19:49:20 +0100 |
commit | efa54f9c460239c23a2014076764d6c6830589e6 (patch) | |
tree | 0bb14829ddbc8ae222c225bbcc3fbf220917d41e /builtin | |
parent | dd282e646c42e3524bc546372c6a648e99b3c9db (diff) | |
download | minetest-efa54f9c460239c23a2014076764d6c6830589e6.tar.gz minetest-efa54f9c460239c23a2014076764d6c6830589e6.tar.bz2 minetest-efa54f9c460239c23a2014076764d6c6830589e6.zip |
Add chatcommand unregister and override API (#5076)
Introduces two functions to unregister and override chatcommands.
minetest.unregister_chatcommand("<name>") and
minetest.override_chatcommand("<name>", {<redifinition>})
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/game/chatcommands.lua | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/builtin/game/chatcommands.lua b/builtin/game/chatcommands.lua index 199b9e964..08dc1bb1d 100644 --- a/builtin/game/chatcommands.lua +++ b/builtin/game/chatcommands.lua @@ -15,6 +15,24 @@ function core.register_chatcommand(cmd, def) core.registered_chatcommands[cmd] = def end +function core.unregister_chatcommand(name) + if core.registered_chatcommands[name] then + core.registered_chatcommands[name] = nil + else + core.log("warning", "Not unregistering chatcommand " ..name.. + " because it doesn't exist.") + end +end + +function core.override_chatcommand(name, redefinition) + local chatcommand = core.registered_chatcommands[name] + assert(chatcommand, "Attempt to override non-existent chatcommand "..name) + for k, v in pairs(redefinition) do + rawset(chatcommand, k, v) + end + core.registered_chatcommands[name] = chatcommand +end + core.register_on_chat_message(function(name, message) local cmd, param = string.match(message, "^/([^ ]+) *(.*)") if not param then |