Giter Site home page Giter Site logo

minetest_yaml's Introduction

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")
-- 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 mod_data directory if exists
    • last load file from world directory
    • return merge the settings together at last, ignore the keys in exclude list.
  • yaml.writeConfig(settings, filename = "config.yml", modName, mode = "wb")
    • first try to save the configuration file in the "mod_data" folder first
    • if fails, save it in the world directory
  • yaml.readYamlFile(filepath)
    • read a YAML format file
  • yaml.readModConfig(filename, modName)
  • yaml.readModDataConfig(filename, modName)
  • yaml.readWorldConfig(filename)
  • yaml.writeYamlFile(filepath, content, mode = "wb")
  • yaml.writeModConfig(filename, content, modName, mode = "wb")
  • yaml.writeModDataConfig(filename, content, modName, mode = "wb")
  • yaml.writeWorldConfig(content, filename, mode = "wb")
  • yaml.readFile(filepath, mode = "rb")
    • read whole file
    • return content if successful
  • yaml.writeFile(filepath, content, mode = "wb")
    • return true if successful
  • yaml.dump(obj)
    • convert the obj to YAML string
  • yaml.eval(str)
    • convert the str to the lua object.
  • yaml.defaults(target, default)
    • merge the default to the target table
    • return target
  • yaml.contains(list, value)
    • whether the list contains the value.

Using the lua-yaml as yaml parser.

minetest_yaml's People

Contributors

snowyu avatar

Stargazers

TehnoTheDragon avatar

Watchers

 avatar  avatar

minetest_yaml's Issues

Mod security: Blocked attempted read

Setting up the quiz mod I got this error from mod security (Minetest 5.6.1)

ModError: Failed to load and run script from /Users/harrywood/Library/Application Support/minetest/mods/quiz/init.lua:
Mod security: Blocked attempted read from /Users/harrywood/Library/Application Support/minetest/mod_data/quiz/config.yml
stack traceback:
	[C]: in function 'open'
	.../Library/Application Support/minetest/mods/yaml/init.lua:44: in function 'readFile'
	.../Library/Application Support/minetest/mods/yaml/init.lua:72: in function 'readModDataConfig'
	.../Library/Application Support/minetest/mods/yaml/init.lua:109: in function 'readConfig'
	.../Library/Application Support/minetest/mods/quiz/init.lua:30: in main chunk
Check debug.txt for details.

I guess it means this needs updating to avoid doing file reads which upset mod security? ...or maybe I'm just doing something wrong.

I did manage to hack it work by modifying this line which sets 'modDataPath'. But I just crudely swapped it to

local modDataPath = WORLD_PATH .. filename

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.