summaryrefslogtreecommitdiff
path: root/builtin/common
diff options
context:
space:
mode:
authorred-001 <red-001@outlook.ie>2017-01-22 08:05:09 +0000
committerLoïc Blot <nerzhul@users.noreply.github.com>2017-03-13 23:56:05 +0100
commitd7bc346981e189851e490f2417ed015a38bca79b (patch)
treec74716238c0851b8d9531544faa4433db22e6a84 /builtin/common
parent9978f5af828550d819890fed1fc56d65838a2c4c (diff)
downloadminetest-d7bc346981e189851e490f2417ed015a38bca79b.tar.gz
minetest-d7bc346981e189851e490f2417ed015a38bca79b.tar.bz2
minetest-d7bc346981e189851e490f2417ed015a38bca79b.zip
[CSM] Add client-sided chat commands (#5092)
Diffstat (limited to 'builtin/common')
-rw-r--r--builtin/common/chatcommands.lua30
1 files changed, 30 insertions, 0 deletions
diff --git a/builtin/common/chatcommands.lua b/builtin/common/chatcommands.lua
new file mode 100644
index 000000000..ef3a24410
--- /dev/null
+++ b/builtin/common/chatcommands.lua
@@ -0,0 +1,30 @@
+-- Minetest: builtin/common/chatcommands.lua
+
+core.registered_chatcommands = {}
+
+function core.register_chatcommand(cmd, def)
+ def = def or {}
+ def.params = def.params or ""
+ def.description = def.description or ""
+ def.privs = def.privs or {}
+ def.mod_origin = core.get_current_modname() or "??"
+ 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 \ No newline at end of file