Go to file
Riceball LEE 88fd78a4d3
feat: add exclude argument to readConfig func
2022-08-01 16:09:30 +08:00
yaml@e4bee338cb build: update lua-yaml 2022-07-28 10:01:14 +08:00
.gitmodules chore: fix submodule url 2022-07-14 14:08:22 +08:00
.luacheckrc first commit 2021-06-18 09:49:06 +08:00
README.md feat: add exclude argument to readConfig func 2022-08-01 16:09:30 +08:00
init.lua feat: add exclude argument to readConfig func 2022-08-01 16:09:30 +08:00
mod.conf docs: update API 2021-06-19 10:03:55 +08:00
pack.sh build: add pack.sh 2021-06-21 22:06:35 +08:00

README.md

Minetest YAML Config Library Mod

ContentDB

Sample YAML Config Format:

# totalPlayTime unit is minute
totalPlayTime: 30
# Whether skip the question which has already be answered correctly.
skipAnswered: 1
# checkInterval unit is seconds
checkInterval: 10
# idleInterval unit is minute
idleInterval: 1
# question list
quiz:
  - id: favorColor
    title: "What's my favor color?"
    answer: red
  - id: theYear
  - title: "What's the year?"
    answer: 2021

Usage

local MOD_NAME = minetest.get_current_modname()
-- load config from file,
-- first load the my-config.yml file in mod directory as default settings
-- then try to load from world directory:
-- the filename in the world folder is MOD_NAME .. "_my-config.yml"
local settings = yaml.readConfig(MOD_NAME, "my-config.yml")
-- save the config file to world directory
-- the default filename is "config.yml" if filename not exists
-- the filename in the world folder is MOD_NAME .. "_" .."my_config.yml"
yaml.writeConfig(settings, "my-config.yml")# totalPlayTime unit is minute
-- append config to file
yaml.writeConfig({ {time = os.time(), content = "content"} }, "my-log.yml", "a")

API

  • yaml.readConfig(modName, filename = "config.yml", exclude = nil)
    • first load the yaml file in mod directory as default settings
    • then load file from world directory
    • return merge the two settings together at last, ignore the keys in exclude list.
  • yaml.writeConfig(settings, filename = "config.yml", modName, mode = "wb")
    • save the config file to the world directory
  • yaml.readYamlFile(filepath)
    • read a YAML format file
  • yaml.readModConfig(filename, modName)
  • yaml.readWorldConfig(filename)
  • yaml.writeYamlFile(filepath, content, mode = "wb")
  • yaml.writeModConfig(filename, content, modName, mode = "wb")
  • yaml.writeWorldConfig(content, filename, mode = "wb")
  • yaml.defaults(target, default)
    • merge the default to the target table
    • return target
  • yaml.readFile(filepath, mode = "rb")
    • read whole file
    • return content if successful
  • yaml.writeFile(filepath, content, mode = "wb")
    • return true if successful

Using the lua-yaml as yaml parser.