Skip to content

Commit

Permalink
Use notice shortcodes for all admonitions in the minetest_docs pages (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rollerozxa authored Dec 15, 2024
1 parent ab5a136 commit 5c89608
Show file tree
Hide file tree
Showing 17 changed files with 329 additions and 111 deletions.
4 changes: 3 additions & 1 deletion content/Filesystem.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Filesystem
Luanti provides various utility functions to help with managing paths, files & directories.

IMPORTANT: Mod security restricts file system access to the mod path (at load time) and the world path later on in secure environments, see [Lua Environment](/Lua_Environment/).
{{< notice info >}}
Mod security restricts file system access to the mod path (at load time) and the world path later on in secure environments, see [Lua Environment](/Lua_Environment/).
{{< /notice >}}

## Paths

Expand Down
12 changes: 9 additions & 3 deletions content/ItemStackMetaData.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# ItemStackMetaData
ItemStackMetaData is a subclass of [[MetaData]] obtained via `stack:get_meta()` allowing for persistent storage of key-value pairs tied to ItemStacks.

WARNING: ItemStack metadata is serialized with ItemStacks, increasing the ItemString length. Inventories have to store multiple ItemStrings, all of which an attacker will try to get to maximum length. Always limit the size of your ItemStackMetaData to keep inventories sendable.
{{< notice warning >}}
ItemStack metadata is serialized with ItemStacks, increasing the ItemString length. Inventories have to store multiple ItemStrings, all of which an attacker will try to get to maximum length. Always limit the size of your ItemStackMetaData to keep inventories sendable.
{{< /notice >}}

## Special Fields

Expand Down Expand Up @@ -31,7 +33,9 @@ Alignment of the displayed item count value is encoded as `x_align + 4 * y_align
| `2` | Centered/Middle | Centered/Middle |
| `3` | Right | Bottom/Down |

TIP: Magic numbers make code unreadable. Add an explanatory comment when setting alignment:
{{< notice tip >}}
Magic numbers make code unreadable. Add an explanatory comment when setting alignment:
{{< /notice >}}

```lua
local meta = stack:get_meta()
Expand Down Expand Up @@ -80,4 +84,6 @@ Allows overriding the tool capabilities specified in the item definition.
- `nil`: Clears the tool capability override, or
- Tool capabilities table: Overrides the defined tool capabilities (see ItemDefinition for the table format)

NOTE: The corresponding `:get_tool_capabilities` is not a method of ItemStackMetaData but rather of the "parent" ItemStack.
{{< notice note >}}
The corresponding `:get_tool_capabilities` is not a method of ItemStackMetaData but rather of the "parent" ItemStack.
{{< /notice >}}
20 changes: 15 additions & 5 deletions content/Lua_Environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ set_global()

Warnings are identified by their location as returned by `debug.getinfo` (`short_src` and `currentline`) and won't be logged twice.

WARNING: Accessing undeclared global variables will be an order of magnitude slower than accessing declared globals due to the executed strictness checking code.
{{< notice warning >}}
Accessing undeclared global variables will be an order of magnitude slower than accessing declared globals due to the executed strictness checking code.
{{< /notice >}}

TIP: These warnings are only triggered at run time as the global variable access or assignment occurs. It is recommended to use a linter like [`luacheck`](https://github.com/mpeterv/luacheck) to detect mistaken global variable usage statically at the time of development.
{{< notice tip >}}
These warnings are only triggered at run time as the global variable access or assignment occurs. It is recommended to use a linter like [`luacheck`](https://github.com/mpeterv/luacheck) to detect mistaken global variable usage statically at the time of development.
{{< /notice >}}

### Checking for global existence

Expand All @@ -51,10 +55,14 @@ As Luanti implements global strictness over a metatable, `rawget(_G, name)` can
#### `core.global_exists(name)`
Returns `true` if a global variable with the given `name` exists (is not `nil`), `false` otherwise. An error is thrown if `name` is not a string.

NOTE: This wraps `rawget(_G, name)` in the end but might be considered more readable as it makes the intention clear.
{{< notice note >}}
This wraps `rawget(_G, name)` in the end but might be considered more readable as it makes the intention clear.
{{< /notice >}}

## Standard Library Extensions
NOTE: It is considered bad practice to extend the standard library yourself, as this may collide with other mods doing the same as well as future engine changes including Lua version upgrades. Put your extensions into distinct API tables instead of modifying Lua's builtin libraries.
{{< notice note >}}
It is considered bad practice to extend the standard library yourself, as this may collide with other mods doing the same as well as future engine changes including Lua version upgrades. Put your extensions into distinct API tables instead of modifying Lua's builtin libraries.
{{< /notice >}}

### `math`

Expand Down Expand Up @@ -114,7 +122,9 @@ for i = 0, 255 do
end
```

WARNING: Platform-independence is not guaranteed: "The definitions of letter, space, and other character groups depend on the current locale." - [Lua 5.1 Reference Manual, section 5.4.1](https://www.lua.org/manual/5.1/manual.html#5.4.1)
{{< notice warning >}}
Platform-independence is not guaranteed: "The definitions of letter, space, and other character groups depend on the current locale." - [Lua 5.1 Reference Manual, section 5.4.1](https://www.lua.org/manual/5.1/manual.html#5.4.1)
{{< /notice >}}

#### `string.split(str, [delim], [include_empty], [max_splits], [sep_is_pattern])`
* `str`: The string to split.
Expand Down
28 changes: 21 additions & 7 deletions content/MetaData.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ Subclasses tie the key-value store to various objects recognized by Luanti:
## Methods

### Getters
NOTE: No type information is stored for values; values will be coerced to and from string as needed. Mods need to know which type they expect in order to call the appropriate getters & setters. Do not rely on coercion to work one way or another; never mix different types.
{{< notice note >}}
No type information is stored for values; values will be coerced to and from string as needed. Mods need to know which type they expect in order to call the appropriate getters & setters. Do not rely on coercion to work one way or another; never mix different types.
{{< /notice >}}

WARNING: [Getters currently resolve the value `${key}` to the value associated with `key`](https://github.com/minetest/minetest/issues/12577).
{{< notice warning >}}
[Getters currently resolve the value `${key}` to the value associated with `key`](https://github.com/minetest/minetest/issues/12577).
{{< /notice >}}

TIP: Due to the limitations of the provided setters & getters, you might favor using your own (de)serialization for coercion of Lua types to strings which can be stored in the string k-v store.
{{< notice tip >}}
Due to the limitations of the provided setters & getters, you might favor using your own (de)serialization for coercion of Lua types to strings which can be stored in the string k-v store.
{{< /notice >}}

* `core.write_json` & `core.parse_json` for Lua tables which are representable as JSON;
* `core.serialize` & `core.deserialize` for arbitrary Lua tables (consisting of tables & primitive types);
Expand Down Expand Up @@ -101,13 +107,17 @@ Setters have no return values; they all take exactly two arguments: Key & value.
**Arguments:**
- `value` - `{type-number}`: The integer value to coerce to a string & associate with `key`

WARNING: Integer refers to a C(++) `int` as internally used by the implementation - usually 32 bits wide - meaning it is unable to represent as large integer numbers as the Lua number type. Be careful when storing integers with large absolute values; they may overflow. Keep `value` between `-2^31` and `2^31 - 1`, both inclusive.
{{< notice warning >}}
Integer refers to a C(++) `int` as internally used by the implementation - usually 32 bits wide - meaning it is unable to represent as large integer numbers as the Lua number type. Be careful when storing integers with large absolute values; they may overflow. Keep `value` between `-2^31` and `2^31 - 1`, both inclusive.
{{< /notice >}}

#### `:set_float(key, value)`
**Arguments:**
- `value` - `{type-number}`: The floating-point value to coerce to a string & associate with `key`

WARNING: The implementation internally uses the C(++) `float` type - usually 32 bits wide - whereas Lua guarantees 64-bit "double-precision" floating point numbers. This may lead to a precision loss. Large numbers in particular may be hardly representable.
{{< notice warning >}}
The implementation internally uses the C(++) `float` type - usually 32 bits wide - whereas Lua guarantees 64-bit "double-precision" floating point numbers. This may lead to a precision loss. Large numbers in particular may be hardly representable.
{{< /notice >}}

#### `:equals(other)`
**Arguments:**
Expand All @@ -126,7 +136,9 @@ Converts the metadata to a Lua table representation.
- `fields`: Table `{[key] = value, ...}`
- Additional fields depending on the subclass

TIP: Use `table = assert(meta:to_table())` to error if the operation failed.
{{< notice tip >}}
Use `table = assert(meta:to_table())` to error if the operation failed.
{{< /notice >}}

#### `:from_table(table)`
Sets the key-value pairs to match those of a given table representation or clears the metadata.
Expand All @@ -139,4 +151,6 @@ Sets the key-value pairs to match those of a given table representation or clear
**Returns:**
- `value` - `{type-bool}`: whether loading the table representation succeeded

TIP: Use `assert(meta:from_table(table))` to error if the operation failed.
{{< notice tip >}}
Use `assert(meta:from_table(table))` to error if the operation failed.
{{< /notice >}}
4 changes: 3 additions & 1 deletion content/ModStorage.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ The granularity of the persisted snapshots is determined by the `map_save_interv
## Backends
Two backends are available for ModStorage: JSON and SQLite3.

WARNING: The JSON backend is incapable of saving raw binary data due to JSON restrictions. Even though the SQLite3 backend supports arbitrary bytestrings, you may not rely on saving arbitrary bytestrings to work, since you can't ensure that the SQLite3 backend is being used.
{{< notice warning >}}
The JSON backend is incapable of saving raw binary data due to JSON restrictions. Even though the SQLite3 backend supports arbitrary bytestrings, you may not rely on saving arbitrary bytestrings to work, since you can't ensure that the SQLite3 backend is being used.
{{< /notice >}}

If the SQLite3 backend is used, it is usually more efficient to leverage the key-value store than to store fully serialized data structures; fully serializing the data takes linear time in the size of the data whereas updating the key-value store only takes linear time in the size of the changes with the SQLite3 backend; for the JSON backend it is irrelevant - it has to fully serialize the data every map save interval anyways, increasing the risk of data loss if writing the file fails due to a hard crash (or freeze) of the Luanti server process.

Expand Down
24 changes: 18 additions & 6 deletions content/Modchannels.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ Returns an object for use with [Methods](#methods). Creates the channel if it do
Used for handling messages received from the client.

### Methods
NOTE: `channel` here means the object returned by `core.mod_channel_join`.
{{< notice note >}}
`channel` here means the object returned by `core.mod_channel_join`.
{{< /notice >}}

#### `channel:leave()`
The server will leave the channel, meaning no more messages from this channel on `core.register_on_modchannel_message`

TIP: Set the channel to `nil` afterwards to free resources
{{< notice tip >}}
Set the channel to `nil` afterwards to free resources
{{< /notice >}}

#### `channel:is_writeable()`
* Returns `bool`: `true` true if the channel is writeable, `false` if it's not.
Expand All @@ -33,7 +37,9 @@ TIP: Set the channel to `nil` afterwards to free resources

Sends to all SSMs and CSMs on the channel.

CAUTION: The message will not if channel is not writable or invalid.
{{< notice info >}}
The message will not if channel is not writable or invalid.
{{< /notice >}}

## Client Side API

Expand Down Expand Up @@ -65,12 +71,16 @@ Used for handling messages received from the client. Is equivalent to the the se
Used to handle signals generated by the mod channel system.

### Methods
NOTE: `channel` here means the object returned by `core.mod_channel_join`.
{{< notice note >}}
`channel` here means the object returned by `core.mod_channel_join`.
{{< /notice >}}

#### `channel:leave()`
The client will leave the channel, meaning no more messages from this channel on `core.register_on_modchannel_message`

TIP: Set the channel to `nil` afterwards to free resources
{{< notice tip >}}
Set the channel to `nil` afterwards to free resources
{{< /notice >}}

#### `channel:is_writeable()`
* Returns `bool`: `true` true if the channel is writeable, `false` if it's not.
Expand All @@ -80,4 +90,6 @@ TIP: Set the channel to `nil` afterwards to free resources

Sends to all SSMs and CSMs on the channel.

CAUTION: The message will not if channel is not writable or invalid.
{{< notice info >}}
The message will not if channel is not writable or invalid.
{{< /notice >}}
20 changes: 15 additions & 5 deletions content/NodeMetaData.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ The client can immediately show the FormSpec; the second approach requires the c

The obvious disadvantage is that FormSpecs can't be dynamically generated in response to user interaction; formspecs must be mostly static. To alleviate this, formspecs provide context-dependant placeholders like the `context` or `current_player` inventory locations (see FormSpec).

IMPORTANT: The `context` inventory location can only be used in FormSpecs using the special `formspec` NodeMetaData field. FormSpecs shown using `core.show_formspec` must use `nodemeta:<X>,<Y>,<Z>` to reference inventories instead.
{{< notice info >}}
The `context` inventory location can only be used in FormSpecs using the special `formspec` NodeMetaData field. FormSpecs shown using `core.show_formspec` must use `nodemeta:<X>,<Y>,<Z>` to reference inventories instead.
{{< /notice >}}

Another disadvantage is that plenty of redundant metadata - often a constant FormSpec - has to be stored with every node. This metadata also has to be sent to clients. Luanti's mapblock compression should be able to compress duplicate substrings - FormSpecs in this case - reasonably well though.

Expand All @@ -58,15 +60,21 @@ NodeMetaData is by default fully sent to clients; the special `formspec` and `in

All other fields do not need to be sent to clients unless you want to explicitly support local mapsaving.

TIP: Mark all other fields as private to reduce traffic.
{{< notice tip >}}
Mark all other fields as private to reduce traffic.
{{< /notice >}}

If you don't want clients to be able to see private NodeMetaData fields - usually to prevent cheating - you must mark them as private.

NOTE: The private marking is tied to a key-value pair.
{{< notice note >}}
The private marking is tied to a key-value pair.
- If the key-value pair is deleted, the private marking is deleted as well.
- If the key-value pair is recreated, the private marking must be recreated as well.
{{< /notice >}}

NOTE: `to_table` and `from_table` do not keep track of which fields were marked as private.
{{< notice note >}}
`to_table` and `from_table` do not keep track of which fields were marked as private.
{{< /notice >}}

**Arguments:**
- `keys` - `{type-string}` or list of `{type-string}`: Either:
Expand All @@ -84,7 +92,9 @@ Extends MetaData `:to_table()` by additionally adding an `inventory` field for
a table `{[listname] = list}` where `list` is a list of ItemStrings
(`""` for empty) with the same length as the size of the inventory list.

TIP: Use `table = assert(meta:to_table())` to error if the operation failed.
{{< notice tip >}}
Use `table = assert(meta:to_table())` to error if the operation failed.
{{< /notice >}}

### `:from_table(table)`
Extends MetaData `:from_table(table)` to add support for the `inventory` field.
Loading

0 comments on commit 5c89608

Please sign in to comment.