Expose and document chatcommands as minetest.registered_chatcommands 4987/head
authorrubenwardy <rubenwardy@gmail.com>
Wed, 28 Dec 2016 13:01:32 +0000 (13:01 +0000)
committerrubenwardy <rubenwardy@gmail.com>
Wed, 4 Jan 2017 20:56:07 +0000 (20:56 +0000)
builtin/game/chatcommands.lua
doc/lua_api.txt

index 71edeb26a0f5a3431a4d3c6bc6e8cde01d3cddf5..eb6edc1c8b58eedd379d00671895a38d30d67dd4 100644 (file)
@@ -4,14 +4,15 @@
 -- Chat command handler
 --
 
-core.chatcommands = {}
+core.registered_chatcommands = {}
+core.chatcommands = core.registered_chatcommands -- BACKWARDS COMPATIBILITY
 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.chatcommands[cmd] = def
+       core.registered_chatcommands[cmd] = def
 end
 
 core.register_on_chat_message(function(name, message)
@@ -19,7 +20,7 @@ core.register_on_chat_message(function(name, message)
        if not param then
                param = ""
        end
-       local cmd_def = core.chatcommands[cmd]
+       local cmd_def = core.registered_chatcommands[cmd]
        if not cmd_def then
                return false
        end
@@ -107,7 +108,7 @@ core.register_chatcommand("help", {
                if param == "" then
                        local msg = ""
                        local cmds = {}
-                       for cmd, def in pairs(core.chatcommands) do
+                       for cmd, def in pairs(core.registered_chatcommands) do
                                if core.check_player_privs(name, def.privs) then
                                        cmds[#cmds + 1] = cmd
                                end
@@ -118,7 +119,7 @@ core.register_chatcommand("help", {
                                        .. " or '/help all' to list everything."
                elseif param == "all" then
                        local cmds = {}
-                       for cmd, def in pairs(core.chatcommands) do
+                       for cmd, def in pairs(core.registered_chatcommands) do
                                if core.check_player_privs(name, def.privs) then
                                        cmds[#cmds + 1] = format_help_line(cmd, def)
                                end
@@ -134,7 +135,7 @@ core.register_chatcommand("help", {
                        return true, "Available privileges:\n"..table.concat(privs, "\n")
                else
                        local cmd = param
-                       local def = core.chatcommands[cmd]
+                       local def = core.registered_chatcommands[cmd]
                        if not def then
                                return false, "Command not available: "..cmd
                        else
@@ -161,7 +162,7 @@ local function handle_grant_command(caller, grantname, grantprivstr)
        if not (caller_privs.privs or caller_privs.basic_privs) then
                return false, "Your privileges are insufficient."
        end
-       
+
        if not core.get_auth_handler().get_auth(grantname) then
                return false, "Player " .. grantname .. " does not exist."
        end
@@ -204,7 +205,7 @@ core.register_chatcommand("grant", {
                local grantname, grantprivstr = string.match(param, "([^ ]+) (.+)")
                if not grantname or not grantprivstr then
                        return false, "Invalid parameters (see /help grant)"
-               end     
+               end
                return handle_grant_command(name, grantname, grantprivstr)
        end,
 })
@@ -215,7 +216,7 @@ core.register_chatcommand("grantme", {
        func = function(name, param)
                if param == "" then
                        return false, "Invalid parameters (see /help grantme)"
-               end     
+               end
                return handle_grant_command(name, name, param)
        end,
 })
index 6166826af241398e963e93241f184bc3c1193d93..6f83039c833c60f8b0e09d6a2527f1e47ff8696c 100644 (file)
@@ -2076,6 +2076,7 @@ Call these functions only at load time!
 
 ### Other registration functions
 * `minetest.register_chatcommand(cmd, chatcommand definition)`
+    * Adds definition to minetest.registered_chatcommands
 * `minetest.register_privilege(name, definition)`
     * `definition`: `"description text"`
     * `definition`: `{ description = "description text", give_to_singleplayer = boolean}`