From b1deb163cfc3858fca8fc1cfe84bfcd956044259 Mon Sep 17 00:00:00 2001 From: alek13 Date: Thu, 25 Apr 2024 20:17:59 +0300 Subject: [PATCH] Add MT class docs --- classes/Settings.lua | 79 ++++++++++++++++++++++++++++++++++++++++++++ minetest_types.lua | 2 +- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 classes/Settings.lua diff --git a/classes/Settings.lua b/classes/Settings.lua new file mode 100644 index 0000000..2347d69 --- /dev/null +++ b/classes/Settings.lua @@ -0,0 +1,79 @@ +--- An interface to read config files in the format of `minetest.conf`. +--- +--- `minetest.settings` is a `Settings` instance that can be used to access the +--- main config file (`minetest.conf`). Instances for other config files can be +--- created via `Settings(filename)`. +--- +--- Engine settings on the `minetest.settings` object have internal defaults that +--- will be returned if a setting is unset. +--- The engine does *not* (yet) read `settingtypes.txt` for this purpose. This +--- means that no defaults will be returned for mod settings. +--- +--- ### Format +--- +--- The settings have the format `key = value`. Example: +--- ``` +--- foo = example text +--- bar = """ +--- Multiline +--- value +--- """ +--- ``` +--- @class Settings +Settings = {} + +--- Returns a value of setting `key` +--- Returns `nil` if `key` is not found. +--- @param key string +--- @return string|nil +function Settings:get(key) end +--- returns a boolean +--- * `default` is the value returned if `key` is not found. +--- * Returns `nil` if `key` is not found and `default` not specified. +--- @overload fun(key:string):boolean|nil +--- @param key string +--- @return boolean|nil +function Settings:get_bool(key, default) end +--- returns a NoiseParams table +--- @param key string +function Settings:get_np_group(key) end +--- * Returns `{flag = true/false, ...}` according to the set flags. +--- * Is currently limited to mapgen flags `mg_flags` and mapgen-specific flags like `mgv5_spflags`. +--- @param key string +function Settings:get_flags(key) end +--- * Setting names can't contain whitespace or any of `="{}#`. +--- * Setting values can't contain the sequence `\n"""`. +--- * Setting names starting with "secure." can't be set on the main settings object (`minetest.settings`). +--- @param key string +--- @param value string +function Settings:set(key, value) end +--- * See documentation for set() above. +--- @param key string +--- @param value boolean +function Settings:set_bool(key, value) end +--- * `value` is a NoiseParams table. +--- * Also, see documentation for set() above. +--- @param key string +--- @param value table +function Settings:set_np_group(key, value) end +--- Returns a boolean (`true` for success) +--- @param key string +--- @return boolean +function Settings:remove(key) end +--- returns `{key1,...}` +--- @return table +function Settings:get_names() end + +--- * Returns a boolean indicating whether `key` exists. +--- * In contrast to the various getter functions, `has()` doesn't consider any default values. +--- * This means that on the main settings object (`minetest.settings`), `get(key)` might return a value even if `has(key)` returns `false`. +--- @param key string +--- @return boolean +function Settings:has(key) end +--- returns a boolean (`true` for success) +--- * Writes changes to file. +--- @return boolean +function Settings:write() end +--- returns `{[key1]=value1,...}` +--- @return table +function Settings:to_table() end diff --git a/minetest_types.lua b/minetest_types.lua index 90ce8c4..46b4cd8 100644 --- a/minetest_types.lua +++ b/minetest_types.lua @@ -775,7 +775,7 @@ function minetest.register_can_bypass_userlimit() end function minetest.register_on_modchannel_message() end -- Setting-related: ---- @type table +--- @type Settings minetest.settings = {} --- Loads a setting from the main settings and