mirror of
https://github.com/appgurueu/modlib.git
synced 2025-01-10 22:47:28 +01:00
Basic schema docs, focus on non-string entry traps
This commit is contained in:
parent
3ff8a8da55
commit
64c487660c
48
Readme.md
48
Readme.md
@ -125,6 +125,54 @@ custom_bluon:write(userdata(), rope)
|
|||||||
assert(rope:to_text() == "\100userdata")
|
assert(rope:to_text() == "\100userdata")
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Schema
|
||||||
|
|
||||||
|
Place a file `schema.lua` in your mod, returning a schema table.
|
||||||
|
|
||||||
|
#### Non-string entries and `minetest.conf`
|
||||||
|
|
||||||
|
Suppose you have the following schema:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
return {
|
||||||
|
type = "table",
|
||||||
|
entries = {
|
||||||
|
[42] = {
|
||||||
|
type = "boolean",
|
||||||
|
description = "The Answer"
|
||||||
|
default = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
And a user sets the following config:
|
||||||
|
|
||||||
|
```conf
|
||||||
|
mod.42 = false
|
||||||
|
```
|
||||||
|
|
||||||
|
It won't work, as the resulting table will be `{["42"] = false}` instead of `{[42] = false}`. In order to make this work, you have to convert the keys yourself:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
return {
|
||||||
|
type = "table",
|
||||||
|
keys = {
|
||||||
|
-- this will convert all keys to numbers
|
||||||
|
type = "number"
|
||||||
|
},
|
||||||
|
entries = {
|
||||||
|
[42] = {
|
||||||
|
type = "boolean",
|
||||||
|
description = "The Answer"
|
||||||
|
default = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
This is best left explicit. First, you shouldn't be using numbered field keys if you want decent `minetest.conf` support, and second, `modlib`'s schema module could only guess in this case, attempting conversion to number / boolean. What if both number and string field were set as possible entries? Should the string field be deleted? And so on.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
### Legacy
|
### Legacy
|
||||||
|
Loading…
Reference in New Issue
Block a user