-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.lua
More file actions
370 lines (305 loc) · 9.96 KB
/
utils.lua
File metadata and controls
370 lines (305 loc) · 9.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
---@meta
---Returns the currently loading mod's name, when loading a mod.
---@return string
---@nodiscard
function minetest.get_current_modname() end
---Returns the directory path for a mod,
---e.g. `"/home/user/.minetest/usermods/modname"`.
---* Returns nil if the mod is not enabled or does not exist (not installed).
---* Works regardless of whether the mod has been loaded yet.
---* Useful for loading additional `.lua` modules or static data from a mod,
---@param modname string
---@return string
---@nodiscard
function minetest.get_modpath(modname) end
---Returns a list of enabled mods, sorted alphabetically.
---
---Does not include disabled mods, even if they are installed.
---@return string[]
---@nodiscard
function minetest.get_modnames() end
---Returns e.g. `"/home/user/.minetest/world"`
---
---Useful for storing custom data in the world directory.
---@return string
---@nodiscard
function minetest.get_worldpath() end
---Returns `true` if the game is launched as singleplayer.
---@return boolean
---@nodiscard
function minetest.is_singleplayer() end
---Table containing API feature flags.
minetest.features = {}
---**Minetest 0.4.7**
minetest.features.glasslike_framed = true
---**Minetest 0.4.7**
minetest.features.nodebox_as_selectionbox = true
---**Minetest 0.4.7**
minetest.features.get_all_craft_recipes_works = true
---The transparency channel of textures can optionally be used on nodes.
---
---**Minetest 0.4.7**
minetest.features.use_texture_alpha = true
---Tree and grass ABMs are no longer done from C++.
---
---**Minetest 0.4.8**
minetest.features.no_legacy_abms = true
---Texture grouping is possible using parentheses.
---
---**Minetest 0.4.11**
minetest.features.texture_names_parens = true
---Unique Area ID for AreaStore:insert_area.
---
---**Minetest 0.4.14**
minetest.features.area_store_custom_ids = true
---`add_entity` supports passing initial staticdata to `on_activate`
---
---**Minetest 0.4.16**
minetest.features.add_entity_with_staticdata = true
---Chat messages are no longer predicted.
---
---**Minetest 0.4.16**
minetest.features.no_chat_message_prediction = true
---The transparency channel of textures can optionally be used on objects (ie: players and lua entities)
---
---**Minetest 5.0.0**
minetest.features.object_use_texture_alpha = true
---Object selectionbox is settable independently from collisionbox.
---
---**Minetest 5.0.0**
minetest.features.object_independent_selectionbox = true
---Specifies whether binary data can be uploaded or downloaded using the HTTP API.
---
---**Minetest 5.1.0**
minetest.features.httpfetch_binary_data = true
---Whether `formspec_version[<version>]` may be used.
---
---**Minetest 5.1.0**
minetest.features.formspec_version_element = true
---Whether AreaStore's IDs are kept on save/load.
---
---**Minetest 5.1.0**
minetest.features.area_store_persistent_ids = true
---Whether minetest.find_path is functional.
---
---**Minetest 5.2.0**
minetest.features.pathfinder_works = true
---Whether Collision info is available to an objects' on_step.
---
---**Minetest 5.3.0**
minetest.features.object_step_has_moveresult = true
---Whether `get_velocity()` and `add_velocity()` can be used on players.
---
---**Minetest 5.4.0**
minetest.features.direct_velocity_on_players = true
---Nodedef's `use_texture_alpha` accepts new string modes.
---
---**Minetest 5.4.0**
minetest.features.use_texture_alpha_string_modes = true
---Degrotate `param2` rotates in units of 1.5° instead of 2° thus changing the range of values from 0-179 to 0-240.
---
---**Minetest 5.5.0**
minetest.features.degrotate_240_steps = true
---ABM supports `min_y` and `max_y` fields in definition.
---
---**Minetest 5.5.0**
minetest.features.abm_min_max_y = true
---`dynamic_add_media` supports passing a table with options.
---
---**Minetest 5.5.0**
minetest.features.dynamic_add_media_table = true
---Allows `get_sky` to return a table instead of separate values.
---
---**Minetest 5.6.0**
minetest.features.get_sky_as_table = true
---Returns `boolean`, `missing_features`
---@param arg string|table<string, boolean>
---@return boolean
---@return table<string, boolean>
---@nodiscard
function minetest.has_feature(arg) end
---@class player_informations
local player_informations = {}
---IP address of the client.
---@type string
player_informations.address = nil
---IPv4 / IPv6
---@type 4|6
player_informations.ip_version = nil
---Seconds since the client connected.
---@type integer
player_informations.connection_uptime = nil
---Protocol version used by the client.
---@type integer
player_informations.protocol_version = nil
---Formspec version supported by the client.
---@type integer
player_informations.formspec_version = nil
---Language code used by the client for translation.
---@type lang_code
player_informations.lang_code = nil
---Minimum round trip time.
---
---**Can be missing if no stats have been collected yet.**
---@type number
player_informations.min_rtt = nil
---Maximum round trip time.
---
---**Can be missing if no stats have been collected yet.**
---@type number
player_informations.max_rtt = nil
---Average round trip time.
---
---**Can be missing if no stats have been collected yet.**
---@type number
player_informations.avg_rtt = nil
---Minimum packet time jitter.
---
---**Can be missing if no stats have been collected yet.**
---@type number
player_informations.min_jitter = nil
---Maximum packet time jitter.
---
---**Can be missing if no stats have been collected yet.**
---@type number
player_informations.max_jitter = nil
---Average packet time jitter.
---
---**Can be missing if no stats have been collected yet.**
---@type number
player_informations.avg_jitter = nil
---Serialization version used by client.
---
---**DEBUG BUILD ONLY**
---@type integer
player_informations.ser_vers = nil
---Major version number.
---
---**DEBUG BUILD ONLY**
---@type integer
player_informations.major = nil
---Minor version number.
---
---**DEBUG BUILD ONLY**
---@type integer
player_informations.minor = nil
---Patch version number.
---
---**DEBUG BUILD ONLY**
---@type integer
player_informations.patch = nil
---Full version string.
---
---**DEBUG BUILD ONLY**
---@type string
player_informations.vers_string = nil
--FIXME: all possible states
---Current client state.
---
---**DEBUG BUILD ONLY**
---@type string
player_informations.state = nil
---Returns a table containing informations about a player.
---@param player_name string
---@return player_informations
---@nodiscard
function minetest.get_player_information(player_name) end
---Creates a directory specified by `path`, creating parent directories if they don't exist.
---
---Returns `true` on success.
---@param path string
---@return boolean
function minetest.mkdir(path) end
---Removes a directory specified by `path`.
---
---If `recursive` is set to `true`, the directory is recursively removed.
---
---Otherwise, the directory will only be removed if it is empty.
---
---Returns `true` on success.
---@param path string
---@param recursive boolean
---@return boolean
function minetest.rmdir(path, recursive) end
---Copies a directory specified by `source` to `destination`.
---
---Any files in `destination` will be overwritten if they already exist.
---
---Returns `true` on success.
---@param source string
---@param destination string
---@return boolean
function minetest.cpdir(source, destination) end
---Moves a directory specified by `source` to `destination`.
---
---If the `destination` is a non-empty directory, then the move will fail.
---
---Returns `true` on success, `false` on failure.
---@param source string
---@param destination string
---@return boolean
function minetest.mvdir(source, destination) end
---Returns the list of entry names in `path`.
---
---`is_dir` is one of:
---* `nil`: return all entries
---* `true`: return only subdirectory names
---* `false`: return only file names
---@param path string
---@param is_dir? boolean
---@return string[]
---@nodiscard
function minetest.get_dir_list(path, is_dir) end
---Replaces contents of file at path with new contents in a safe (atomic) way.
---
---Use this instead of below code when writing e.g. database files:
---```lua
---local f = io.open(path, "wb"); f:write(content); f:close()
---```
---@param path string
---@param content string
function minetest.safe_file_write(path, content) end
---Use this for informational purposes only.
---
---The information in the returned table does not represent the capabilities of the engine, nor is it reliable or verifiable.
---
---Compatible forks will have an entirely different name and version.
---@class engine_version
local engine_version = {}
---Name of the project, eg, `"Minetest"`.
---@type string
engine_version.project = nil
---Simple version, eg, `"1.2.3-dev"`.
---@type string
engine_version.string = nil
---Full git version (only set if available), eg, `"1.2.3-dev-01234567-dirty"`.
---@type string
engine_version.hash = nil
---Returns a table containing components of the engine version.
---@return engine_version
---@nodiscard
function minetest.get_version() end
---Returns the `sha1` hash of `data`.
---@param data string
---@param raw? boolean Default: `false`
---@return string
---@nodiscard
function minetest.sha1(data, raw) end
---Encode a PNG image and return it in string form.
---
---The data is one-dimensional, starting in the upper left corner of the image and laid out in scanlines going from left to right, then top to bottom.
---
---Please note that it's not safe to use `string.char` to generate raw data, use `colorspec_to_bytes` to generate raw RGBA values in a predictable way.
---
---The resulting PNG image is always 32-bit. Palettes are not supported at the moment.
---
---You may use this to procedurally generate textures during server init.
---@param width integer Width of the image
---@param height integer Height of the image
---@param data table Image data, one of:
---* array table of `ColorSpec`, length must be `width*height`
---* string with raw RGBA pixels, length must be `width*height*4`
---@param compression 0|1|2|3|4|5|6|7|8|9
---@return string
---@nodiscard
function minetest.encode_png(width, height, data, compression) end