Go to file
Lars Mueller d016d9e768 Increase help formspec size by 1.5x 2022-07-26 21:26:01 +02:00
textures Optimize images 2020-05-24 13:05:27 +02:00
Readme.md rolling-8 2020-02-29 12:55:29 +01:00
help.lua Increase help formspec size by 1.5x 2022-07-26 21:26:01 +02:00
init.lua Code quality: use new modlib functionality 2020-07-30 00:06:21 +02:00
main.lua Increase help formspec size by 1.5x 2022-07-26 21:26:01 +02:00
mod.conf Updates via shellscript 2019-08-12 12:37:54 +02:00
override.lua Help dialog: group by mod for >= 3 commands 2020-07-02 15:55:07 +02:00
screenshot.png Optimize images 2020-05-24 13:05:27 +02:00
test.lua Help dialog: group by mod for >= 3 commands 2020-07-02 15:55:07 +02:00
trie.lua 🎃 Halloween Update 2019-10-31 21:54:06 +01:00

Readme.md

Chatcommand Library (cmdlib)

Making chatcommands a pleasure to use.

About

Adds a few features to chatcommands useful for devs (parsing, trees, forbidden privs, etc), and other features useful for players, such as suggestions, command trees, and a better help command.

Note : Overrides /help chatcommand and builtin functions (minetest.register_chatcommand), replaces chatcommand handler.

Depends on modlib. IntelliJ IDEA with EmmyLua plugin project. Code & media by Lars Mueller aka LMD or appguru(eu). Licensed under GPLv3.

Links : GitHub, Minetest Forum, Content DB

Screenshot

Screenshot

API

A few API methods are listed below. Browse the code for more. Three parts are provided by cmdlib :

  • Trie data structure
  • Help command
  • Chatcommand utils (main part)

cmdlib.register(name, def)

Name (name) : Chatcommand name, including whitespaces (such as mod command)

Definition (def) : Table with entries params, custom_syntax, implicit_call, description, privs, and func

  • Params: Argument syntax, string, format of <required_param> [optional_param], or {param} for zero or more occurrences. Needs required params first, then optional ones, and finally, an optional list
  • Custom syntax: Flag, if set to true, func will be called with string params (empty string if none given). Automatically true if params string is invalid.
  • Implicit call: Metacommands only. If set to true, chatcommand will be called instead of proposing subcommand. Automatically true if params are specified.
  • Description: Text describing the usage of the chatcommand
  • Privileges: Table with privs which are required or should be missing, like {priv1=true, priv2=false}
  • Function: Function being invoked with sendername and a table of parameters ({param1="..."}), {params} will be supplied as tables

trie.new()

Creates (returns) a new trie (empty table).

trie.insert(trie, word, [value], [overwrite])

Inserts a word into a trie. value is optional (defaults to true). overwrite is optional as well and defaults to false. Returns previous value.

trie.remove(trie, word)

Removes word from trie. Returns previous value.

trie.get(trie, word)

Check if trie contains word and return corresponding value, or nil.

trie.search(trie, word)

Search for word in trie. Return value if found, else (nil, closest word, value) or nil if no closest word exists.

Invocation

Invoke a chatcommand by giving the params separated by whitespaces (like /cmd subcmd param1 param2).

Help

Use /help [query] to open the extremely useful formspec shown above.