Skip to content

Commit efa54f9

Browse files
octaciannerzhul
authored andcommittedJan 20, 2017
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>})
1 parent dd282e6 commit efa54f9

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
 

‎builtin/game/chatcommands.lua

+18
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ function core.register_chatcommand(cmd, def)
1515
core.registered_chatcommands[cmd] = def
1616
end
1717

18+
function core.unregister_chatcommand(name)
19+
if core.registered_chatcommands[name] then
20+
core.registered_chatcommands[name] = nil
21+
else
22+
core.log("warning", "Not unregistering chatcommand " ..name..
23+
" because it doesn't exist.")
24+
end
25+
end
26+
27+
function core.override_chatcommand(name, redefinition)
28+
local chatcommand = core.registered_chatcommands[name]
29+
assert(chatcommand, "Attempt to override non-existent chatcommand "..name)
30+
for k, v in pairs(redefinition) do
31+
rawset(chatcommand, k, v)
32+
end
33+
core.registered_chatcommands[name] = chatcommand
34+
end
35+
1836
core.register_on_chat_message(function(name, message)
1937
local cmd, param = string.match(message, "^/([^ ]+) *(.*)")
2038
if not param then

‎doc/lua_api.txt

+4
Original file line numberDiff line numberDiff line change
@@ -2077,6 +2077,10 @@ Call these functions only at load time!
20772077
### Other registration functions
20782078
* `minetest.register_chatcommand(cmd, chatcommand definition)`
20792079
* Adds definition to minetest.registered_chatcommands
2080+
* `minetest.override_chatcommand(name, redefinition)`
2081+
* Overrides fields of a chatcommand registered with register_chatcommand.
2082+
* `minetest.unregister_chatcommand(name)`
2083+
* Unregisters a chatcommands registered with register_chatcommand.
20802084
* `minetest.register_privilege(name, definition)`
20812085
* `definition`: `"description text"`
20822086
* `definition`: `{ description = "description text", give_to_singleplayer = boolean}`

0 commit comments

Comments
 (0)
Please sign in to comment.