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,6 +170,7 @@ from the available ones of the following files:
Examples of sound parameter tables: Examples of sound parameter tables:
```lua
-- Play locationless -- Play locationless
{ {
gain = 1.0, -- default gain = 1.0, -- default
@ -190,6 +191,7 @@ Examples of sound parameter tables:
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
```lua
{x=num, y=num, z=num} {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
```lua
{place_center_x = true, place_center_y=false, place_center_z=true} {place_center_x = true, place_center_y=false, place_center_z=true}
```
is equivalent to is equivalent to
```lua
{place_center_x = true, noplace_center_y=true, place_center_z=true} {place_center_x = true, noplace_center_y=true, place_center_z=true}
```
which is equivalent to which is equivalent to
```lua
"place_center_x, noplace_center_y, place_center_z" "place_center_x, noplace_center_y, place_center_z"
```
or even or even
```lua
"place_center_x, place_center_z" "place_center_x, place_center_z"
```
since, by default, no schematic attributes are set. since, by default, no schematic attributes are set.
@ -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:
```lua
local ray = Raycast(...) local ray = Raycast(...)
for pointed_thing in ray do 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.
@ -1292,12 +1306,15 @@ It can be created via `Raycast(pos1, pos2, objects, liquids)` or
### 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,6 +1326,7 @@ 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"
@ -1478,6 +1496,7 @@ 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},
@ -1500,9 +1519,11 @@ Same as `image`, but does not accept a `position`; the position is instead deter
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,
@ -1530,3 +1551,4 @@ Same as `image`, but does not accept a `position`; the position is instead deter
texture = "image.png", texture = "image.png",
-- ^ Uses texture (string) -- ^ Uses texture (string)
} }
```

File diff suppressed because it is too large Load Diff

@ -22,6 +22,7 @@ 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>,
@ -30,6 +31,7 @@ The "gamedata" table is read when calling `core.start()`. It should contain:
selected_world = <index>, -- 0 for client mode selected_world = <index>, -- 0 for client mode
singleplayer = <true/false>, singleplayer = <true/false>,
} }
```
Functions Functions
@ -116,6 +118,7 @@ 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",
@ -141,12 +144,14 @@ Used by `HTTPApiTable.fetch` and `HTTPApiTable.fetch_async`.
-- 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
@ -163,6 +168,7 @@ Passed to `HTTPApiTable.fetch` callback. Returned by
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)`