Skip to content

Commit

Permalink
Add chatcommand unregister and override API (#5076)
Browse files Browse the repository at this point in the history
Introduces two functions to unregister and override chatcommands.
minetest.unregister_chatcommand("<name>") and
minetest.override_chatcommand("<name>", {<redifinition>})
  • Loading branch information
octacian authored and nerzhul committed Jan 20, 2017
1 parent dd282e6 commit efa54f9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions builtin/game/chatcommands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions doc/lua_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2077,6 +2077,10 @@ Call these functions only at load time!
### Other registration functions
* `minetest.register_chatcommand(cmd, chatcommand definition)`
* Adds definition to minetest.registered_chatcommands
* `minetest.override_chatcommand(name, redefinition)`
* Overrides fields of a chatcommand registered with register_chatcommand.
* `minetest.unregister_chatcommand(name)`
* Unregisters a chatcommands registered with register_chatcommand.
* `minetest.register_privilege(name, definition)`
* `definition`: `"description text"`
* `definition`: `{ description = "description text", give_to_singleplayer = boolean}`
Expand Down

0 comments on commit efa54f9

Please sign in to comment.