Use Lua code blocks in lua_api.md

This commit is contained in:
AFCMS 2023-04-26 20:09:08 +02:00 committed by GitHub
parent 9c90358912
commit d197ff0f9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 2504 additions and 2312 deletions

@ -170,26 +170,28 @@ from the available ones of the following files:
Examples of sound parameter tables: Examples of sound parameter tables:
-- Play locationless ```lua
{ -- Play locationless
{
gain = 1.0, -- default gain = 1.0, -- default
} }
-- Play locationless, looped -- Play locationless, looped
{ {
gain = 1.0, -- default gain = 1.0, -- default
loop = true, loop = true,
} }
-- Play in a location -- Play in a location
{ {
pos = {x = 1, y = 2, z = 3}, pos = {x = 1, y = 2, z = 3},
gain = 1.0, -- default gain = 1.0, -- default
} }
-- Play connected to an object, looped -- Play connected to an object, looped
{ {
object = <an ObjectRef>, object = <an ObjectRef>,
gain = 1.0, -- default gain = 1.0, -- default
loop = true, loop = true,
} }
```
Looped sounds must either be connected to an object or played locationless. Looped sounds must either be connected to an object or played locationless.
@ -205,7 +207,9 @@ Representations of simple things
### Position/vector ### Position/vector
{x=num, y=num, z=num} ```lua
{x=num, y=num, z=num}
```
For helper functions see "Vector helpers". For helper functions see "Vector helpers".
@ -231,19 +235,27 @@ is present, mapped to a boolean of any value, the specified flag is unset.
E.g. A flag field of value E.g. A flag field of value
{place_center_x = true, place_center_y=false, place_center_z=true} ```lua
{place_center_x = true, place_center_y=false, place_center_z=true}
```
is equivalent to is equivalent to
{place_center_x = true, noplace_center_y=true, place_center_z=true} ```lua
{place_center_x = true, noplace_center_y=true, place_center_z=true}
```
which is equivalent to which is equivalent to
"place_center_x, noplace_center_y, place_center_z" ```lua
"place_center_x, noplace_center_y, place_center_z"
```
or even or even
"place_center_x, place_center_z" ```lua
"place_center_x, place_center_z"
```
since, by default, no schematic attributes are set. since, by default, no schematic attributes are set.
@ -996,14 +1008,14 @@ Please do not try to access the reference until the camera is initialized, other
* `get_fov()` * `get_fov()`
* Returns a table with X, Y, maximum and actual FOV in degrees: * Returns a table with X, Y, maximum and actual FOV in degrees:
```lua ```lua
{ {
x = number, x = number,
y = number, y = number,
max = number, max = number,
actual = number actual = number
} }
``` ```
* `get_pos()` * `get_pos()`
* Returns position of camera with view bobbing * Returns position of camera with view bobbing
@ -1053,7 +1065,7 @@ Methods:
* `get_physics_override()` * `get_physics_override()`
* returns: * returns:
```lua ```lua
{ {
speed = float, speed = float,
jump = float, jump = float,
@ -1062,7 +1074,7 @@ Methods:
sneak_glitch = boolean, sneak_glitch = boolean,
new_move = boolean, new_move = boolean,
} }
``` ```
* `get_override_pos()` * `get_override_pos()`
* returns override position * returns override position
@ -1075,18 +1087,18 @@ Methods:
* `get_movement_acceleration()` * `get_movement_acceleration()`
* returns acceleration of the player in different environments: * returns acceleration of the player in different environments:
```lua ```lua
{ {
fast = float, fast = float,
air = float, air = float,
default = float, default = float,
} }
``` ```
* `get_movement_speed()` * `get_movement_speed()`
* returns player's speed in different environments: * returns player's speed in different environments:
```lua ```lua
{ {
walk = float, walk = float,
jump = float, jump = float,
@ -1094,19 +1106,19 @@ Methods:
fast = float, fast = float,
climb = float, climb = float,
} }
``` ```
* `get_movement()` * `get_movement()`
* returns player's movement in different environments: * returns player's movement in different environments:
```lua ```lua
{ {
liquid_fluidity = float, liquid_fluidity = float,
liquid_sink = float, liquid_sink = float,
liquid_fluidity_smooth = float, liquid_fluidity_smooth = float,
gravity = float, gravity = float,
} }
``` ```
* `get_last_look_horizontal()`: * `get_last_look_horizontal()`:
* returns last look horizontal angle * returns last look horizontal angle
@ -1115,7 +1127,7 @@ Methods:
* `get_control()`: * `get_control()`:
* returns pressed player controls * returns pressed player controls
```lua ```lua
{ {
up = boolean, up = boolean,
down = boolean, down = boolean,
@ -1128,7 +1140,7 @@ Methods:
dig = boolean, dig = boolean,
place = boolean, place = boolean,
} }
``` ```
* `get_armor_groups()` * `get_armor_groups()`
* returns a table with the armor group ratings * returns a table with the armor group ratings
@ -1176,10 +1188,12 @@ Can be obtained via `minetest.get_meta(pos)`.
A raycast on the map. It works with selection boxes. A raycast on the map. It works with selection boxes.
Can be used as an iterator in a for loop as: Can be used as an iterator in a for loop as:
local ray = Raycast(...) ```lua
for pointed_thing in ray do local ray = Raycast(...)
for pointed_thing in ray do
... ...
end end
```
The map is loaded as the ray advances. If the map is modified after the The map is loaded as the ray advances. If the map is modified after the
`Raycast` is created, the changes may or may not have an effect on the object. `Raycast` is created, the changes may or may not have an effect on the object.
@ -1207,7 +1221,7 @@ It can be created via `Raycast(pos1, pos2, objects, liquids)` or
#### Node Definition #### Node Definition
```lua ```lua
{ {
has_on_construct = bool, -- Whether the node has the on_construct callback defined has_on_construct = bool, -- Whether the node has the on_construct callback defined
has_on_destruct = bool, -- Whether the node has the on_destruct callback defined has_on_destruct = bool, -- Whether the node has the on_destruct callback defined
has_after_destruct = bool, -- Whether the node has the after_destruct callback defined has_after_destruct = bool, -- Whether the node has the after_destruct callback defined
@ -1263,13 +1277,13 @@ It can be created via `Raycast(pos1, pos2, objects, liquids)` or
legacy_facedir_simple = bool, -- Whether to use old facedir legacy_facedir_simple = bool, -- Whether to use old facedir
legacy_wallmounted = bool -- Whether to use old wallmounted legacy_wallmounted = bool -- Whether to use old wallmounted
move_resistance = <number>, -- How slow players can move through the node *May not exist* move_resistance = <number>, -- How slow players can move through the node *May not exist*
} }
``` ```
#### Item Definition #### Item Definition
```lua ```lua
{ {
name = string, -- Name of the item e.g. "default:stone" name = string, -- Name of the item e.g. "default:stone"
description = string, -- Description of the item e.g. "Stone" description = string, -- Description of the item e.g. "Stone"
type = string, -- Item type: "none", "node", "craftitem", "tool" type = string, -- Item type: "none", "node", "craftitem", "tool"
@ -1286,18 +1300,21 @@ It can be created via `Raycast(pos1, pos2, objects, liquids)` or
sound_place = SimpleSoundSpec, -- Sound played when placed sound_place = SimpleSoundSpec, -- Sound played when placed
sound_place_failed = SimpleSoundSpec, -- Sound played when placement failed sound_place_failed = SimpleSoundSpec, -- Sound played when placement failed
node_placement_prediction = string -- Node placed in client until server catches up node_placement_prediction = string -- Node placed in client until server catches up
} }
``` ```
----------------- -----------------
### Chat command definition (`register_chatcommand`) ### Chat command definition (`register_chatcommand`)
{ ```lua
{
params = "<name> <privilege>", -- Short parameter description params = "<name> <privilege>", -- Short parameter description
description = "Remove privilege from player", -- Full description description = "Remove privilege from player", -- Full description
func = function(param), -- Called when command is run. func = function(param), -- Called when command is run.
-- Returns boolean success and text output. -- Returns boolean success and text output.
} }
```
### Server info ### Server info
```lua ```lua
{ {
@ -1309,29 +1326,30 @@ It can be created via `Raycast(pos1, pos2, objects, liquids)` or
``` ```
### HUD Definition (`hud_add`, `hud_get`) ### HUD Definition (`hud_add`, `hud_get`)
```lua ```lua
{ {
hud_elem_type = "image", -- see HUD element types, default "text" hud_elem_type = "image", -- see HUD element types, default "text"
-- ^ type of HUD element, can be either of "image", "text", "statbar", or "inventory" -- ^ type of HUD element, can be either of "image", "text", "statbar", or "inventory"
position = {x=0.5, y=0.5}, position = {x=0.5, y=0.5},
-- ^ Left corner position of element, default `{x=0,y=0}`. -- ^ Left corner position of element, default `{x=0,y=0}`.
name = "<name>", -- default "" name = "<name>", -- default ""
scale = {x=2, y=2}, -- default {x=0,y=0} scale = {x=2, y=2}, -- default {x=0,y=0}
text = "<text>", -- default "" text = "<text>", -- default ""
number = 2, -- default 0 number = 2, -- default 0
item = 3, -- default 0 item = 3, -- default 0
-- ^ Selected item in inventory. 0 for no item selected. -- ^ Selected item in inventory. 0 for no item selected.
direction = 0, -- default 0 direction = 0, -- default 0
-- ^ Direction: 0: left-right, 1: right-left, 2: top-bottom, 3: bottom-top -- ^ Direction: 0: left-right, 1: right-left, 2: top-bottom, 3: bottom-top
alignment = {x=0, y=0}, -- default {x=0, y=0} alignment = {x=0, y=0}, -- default {x=0, y=0}
-- ^ See "HUD Element Types" -- ^ See "HUD Element Types"
offset = {x=0, y=0}, -- default {x=0, y=0} offset = {x=0, y=0}, -- default {x=0, y=0}
-- ^ See "HUD Element Types" -- ^ See "HUD Element Types"
size = { x=100, y=100 }, -- default {x=0, y=0} size = { x=100, y=100 }, -- default {x=0, y=0}
-- ^ Size of element in pixels -- ^ Size of element in pixels
style = 0, style = 0,
-- ^ For "text" elements sets font style: bitfield with 1 = bold, 2 = italic, 4 = monospace -- ^ For "text" elements sets font style: bitfield with 1 = bold, 2 = italic, 4 = monospace
} }
``` ```
Escape sequences Escape sequences
@ -1478,7 +1496,8 @@ Same as `image`, but does not accept a `position`; the position is instead deter
### Particle definition (`add_particle`) ### Particle definition (`add_particle`)
{ ```lua
{
pos = {x=0, y=0, z=0}, pos = {x=0, y=0, z=0},
velocity = {x=0, y=0, z=0}, velocity = {x=0, y=0, z=0},
acceleration = {x=0, y=0, z=0}, acceleration = {x=0, y=0, z=0},
@ -1499,11 +1518,13 @@ Same as `image`, but does not accept a `position`; the position is instead deter
-- ^ optional, specifies how to animate the particle texture -- ^ optional, specifies how to animate the particle texture
glow = 0 glow = 0
-- ^ optional, specify particle self-luminescence in darkness -- ^ optional, specify particle self-luminescence in darkness
} }
```
### `ParticleSpawner` definition (`add_particlespawner`) ### `ParticleSpawner` definition (`add_particlespawner`)
{ ```lua
{
amount = 1, amount = 1,
time = 1, time = 1,
-- ^ If time is 0 has infinite lifespan and spawns the amount on a per-second base -- ^ If time is 0 has infinite lifespan and spawns the amount on a per-second base
@ -1529,4 +1550,5 @@ Same as `image`, but does not accept a `position`; the position is instead deter
-- ^ vertical: if true faces player using y axis only -- ^ vertical: if true faces player using y axis only
texture = "image.png", texture = "image.png",
-- ^ Uses texture (string) -- ^ Uses texture (string)
} }
```

File diff suppressed because it is too large Load Diff

@ -22,14 +22,16 @@ Gamedata
The "gamedata" table is read when calling `core.start()`. It should contain: The "gamedata" table is read when calling `core.start()`. It should contain:
{ ```lua
{
playername = <name>, playername = <name>,
password = <password>, password = <password>,
address = <IP/address>, address = <IP/address>,
port = <port>, port = <port>,
selected_world = <index>, -- 0 for client mode selected_world = <index>, -- 0 for client mode
singleplayer = <true/false>, singleplayer = <true/false>,
} }
```
Functions Functions
@ -116,7 +118,8 @@ HTTP Requests
Used by `HTTPApiTable.fetch` and `HTTPApiTable.fetch_async`. Used by `HTTPApiTable.fetch` and `HTTPApiTable.fetch_async`.
{ ```lua
{
url = "http://example.org", url = "http://example.org",
timeout = 10, timeout = 10,
@ -140,14 +143,16 @@ Used by `HTTPApiTable.fetch` and `HTTPApiTable.fetch_async`.
multipart = boolean multipart = boolean
-- Optional, if true performs a multipart HTTP request. -- Optional, if true performs a multipart HTTP request.
-- Default is false. -- Default is false.
} }
```
### `HTTPRequestResult` definition ### `HTTPRequestResult` definition
Passed to `HTTPApiTable.fetch` callback. Returned by Passed to `HTTPApiTable.fetch` callback. Returned by
`HTTPApiTable.fetch_async_get`. `HTTPApiTable.fetch_async_get`.
{ ```lua
{
completed = true, completed = true,
-- If true, the request has finished (either succeeded, failed or timed -- If true, the request has finished (either succeeded, failed or timed
-- out) -- out)
@ -162,7 +167,8 @@ Passed to `HTTPApiTable.fetch` callback. Returned by
-- HTTP status code -- HTTP status code
data = "response" data = "response"
} }
```
Formspec Formspec
@ -209,6 +215,7 @@ GUI
* name of current renderer, e.g. "OpenGL 4.6" * name of current renderer, e.g. "OpenGL 4.6"
* `core.get_window_info()`: Same as server-side `get_player_window_information` API. * `core.get_window_info()`: Same as server-side `get_player_window_information` API.
```lua
-- Note that none of these things are constant, they are likely to change -- Note that none of these things are constant, they are likely to change
-- as the player resizes the window and moves it between monitors -- as the player resizes the window and moves it between monitors
-- --
@ -241,6 +248,7 @@ GUI
-- Equal to the setting `hud_scaling` multiplied by `dpi / 96` -- Equal to the setting `hud_scaling` multiplied by `dpi / 96`
real_hud_scaling = 1, real_hud_scaling = 1,
} }
```
@ -262,7 +270,7 @@ Package - content which is downloadable from the content db, may or may not be i
Ex: Ex:
``` ```lua
{ {
mods = "/home/user/.minetest/mods", mods = "/home/user/.minetest/mods",
share = "/usr/share/minetest/mods", share = "/usr/share/minetest/mods",
@ -281,7 +289,7 @@ Package - content which is downloadable from the content db, may or may not be i
* `core.get_games()` -> table of all games (possible in async calls) * `core.get_games()` -> table of all games (possible in async calls)
* `name` in return value is deprecated, use `title` instead. * `name` in return value is deprecated, use `title` instead.
* returns a table (ipairs) with values: * returns a table (ipairs) with values:
```lua
{ {
id = <id>, id = <id>,
path = <full path to game>, path = <full path to game>,
@ -289,12 +297,13 @@ Package - content which is downloadable from the content db, may or may not be i
title = <title of game>, title = <title of game>,
menuicon_path = <full path to menuicon>, menuicon_path = <full path to menuicon>,
author = "author", author = "author",
DEPRECATED: --DEPRECATED:
addon_mods_paths = {[1] = <path>,}, addon_mods_paths = {[1] = <path>,},
} }
```
* `core.get_content_info(path)` * `core.get_content_info(path)`
* returns * returns
```lua
{ {
name = "technical_id", name = "technical_id",
type = "mod" or "modpack" or "game" or "txp", type = "mod" or "modpack" or "game" or "txp",
@ -305,18 +314,20 @@ Package - content which is downloadable from the content db, may or may not be i
depends = {"mod", "names"}, -- mods only depends = {"mod", "names"}, -- mods only
optional_depends = {"mod", "names"}, -- mods only optional_depends = {"mod", "names"}, -- mods only
} }
```
* `core.check_mod_configuration(world_path, mod_paths)` * `core.check_mod_configuration(world_path, mod_paths)`
* Checks whether configuration is valid. * Checks whether configuration is valid.
* `world_path`: path to the world * `world_path`: path to the world
* `mod_paths`: list of enabled mod paths * `mod_paths`: list of enabled mod paths
* returns: * returns:
```lua
{ {
is_consistent = true, -- true is consistent, false otherwise is_consistent = true, -- true is consistent, false otherwise
unsatisfied_mods = {}, -- list of mod specs unsatisfied_mods = {}, -- list of mod specs
satisfied_mods = {}, -- list of mod specs satisfied_mods = {}, -- list of mod specs
error_message = "", -- message or nil error_message = "", -- message or nil
} }
```
Logging Logging
------- -------
@ -346,7 +357,7 @@ Worlds
* `core.get_worlds()` -> list of worlds (possible in async calls) * `core.get_worlds()` -> list of worlds (possible in async calls)
* returns * returns
```lua
{ {
[1] = { [1] = {
path = <full path to world>, path = <full path to world>,
@ -354,6 +365,7 @@ Worlds
gameid = <gameid of world>, gameid = <gameid of world>,
}, },
} }
```
* `core.create_world(worldname, gameid, init_settings)` * `core.create_world(worldname, gameid, init_settings)`
* `core.delete_world(index)` * `core.delete_world(index)`