utilities.lua 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. ---@meta
  2. ---Utilities
  3. ------------
  4. -- Returns the currently loading mod's name, when loading a mod.
  5. ---@return string
  6. function minetest.get_current_modname() end
  7. -- * Returns the directory path for a mod,
  8. -- e.g. `"/home/user/.minetest/usermods/modname"`.
  9. -- * Returns nil if the mod is not enabled or does not exist (not installed).
  10. -- * Works regardless of whether the mod has been loaded yet.
  11. -- * Useful for loading additional `.lua` modules or static data from a mod,
  12. -- or checking if a mod is enabled.
  13. ---@param modname string
  14. ---@return string
  15. function minetest.get_modpath(modname) end
  16. -- * Returns a list of enabled mods, sorted alphabetically.
  17. -- * Does not include disabled mods, even if they are installed.
  18. ---@return string[]
  19. function minetest.get_modnames() end
  20. -- * Returns a table containing information about the
  21. -- current game. Note that other meta information (e.g. version/release number)
  22. -- can be manually read from `game.conf` in the game's root directory.
  23. ---@return {id: string, title: string, author: string, path: string}
  24. function minetest.get_game_info() end
  25. -- * Returns e.g. `"/home/user/.minetest/world"`
  26. -- * Useful for storing custom data
  27. ---@return string
  28. function minetest.get_worldpath() end
  29. ---@return boolean
  30. function minetest.is_singleplayer() end
  31. -- Table containing API feature flags.
  32. ---@class mt.Feature
  33. ---@field glasslike_framed boolean (0.4.7).
  34. ---@field nodebox_as_selectionbox boolean (0.4.7).
  35. ---@field get_all_craft_recipes_works boolean (0.4.7).
  36. -- The transparency channel of textures can optionally be used on nodes (0.4.7).
  37. ---@field use_texture_alpha boolean
  38. -- Tree and grass ABMs are no longer done from C++ (0.4.8).
  39. ---@field no_legacy_abms boolean
  40. -- Texture grouping is possible using parentheses (0.4.11).
  41. ---@field texture_names_parens boolean
  42. -- Unique Area ID for AreaStore:insert_area (0.4.14).
  43. ---@field area_store_custom_ids boolean
  44. -- `add_entity` supports passing initial staticdata to `on_activate` (0.4.16).
  45. ---@field add_entity_with_staticdata boolean
  46. -- Chat messages are no longer predicted (0.4.16).
  47. ---@field no_chat_message_prediction boolean
  48. -- The transparency channel of textures can optionally be used on
  49. -- objects (ie: players and lua entities) (5.0.0).
  50. ---@field object_use_texture_alpha boolean
  51. -- Object selectionbox is settable independently from collisionbox (5.0.0).
  52. ---@field object_independent_selectionbox boolean
  53. -- Specifies whether binary data can be uploaded or downloaded using
  54. -- the HTTP API (5.1.0).
  55. ---@field httpfetch_binary_data boolean
  56. -- Whether formspec_version[<version>] may be used (5.1.0).
  57. ---@field formspec_version_element boolean
  58. -- Whether AreaStore's IDs are kept on save/load (5.1.0).
  59. ---@field area_store_persistent_ids boolean
  60. -- Whether minetest.find_path is functional (5.2.0).
  61. ---@field pathfinder_works boolean
  62. -- Whether Collision info is available to an objects' on_step (5.3.0).
  63. ---@field object_step_has_moveresult boolean
  64. -- Whether `get_velocity()` and `add_velocity()` can be used on players (5.4.0).
  65. ---@field direct_velocity_on_players boolean
  66. -- `nodedef`'s `use_texture_alpha` accepts new string modes (5.4.0).
  67. ---@field use_texture_alpha_string_modes boolean
  68. -- `degrotate` param2 rotates in units of 1.5° instead of 2°
  69. -- thus changing the range of values from 0-179 to 0-240 (5.5.0).
  70. ---@field degrotate_240_steps boolean
  71. -- ABM supports `min_y` and `max_y` fields in definition (5.5.0).
  72. ---@field abm_min_max_y boolean
  73. -- `dynamic_add_media` supports passing a table with options (5.5.0).
  74. ---@field dynamic_add_media_table boolean
  75. -- Particlespawners support texpools and animation of properties,
  76. -- particle textures support smooth fade and scale animations, and
  77. -- sprite-sheet particle animations can by synced to the lifetime
  78. -- of individual particles (5.6.0).
  79. ---@field particlespawner_tweenable boolean
  80. -- Allows get_sky to return a table instead of separate values (5.6.0).
  81. ---@field get_sky_as_table boolean
  82. -- `VoxelManip:get_light_data` accepts an optional buffer argument (5.7.0).
  83. ---@field get_light_data_buffer boolean
  84. -- When using a mod storage backend that is not "files" or "dummy",
  85. -- the amount of data in mod storage is not constrained by
  86. -- the amount of RAM available. (5.7.0).
  87. ---@field mod_storage_on_disk boolean
  88. -- "zstd" method for compress/decompress (5.7.0).
  89. ---@field compress_zstd boolean
  90. minetest.features = {}
  91. ---@param arg string | table<mt.Feature, boolean>
  92. ---@return boolean, table<mt.Feature, boolean> missing
  93. function minetest.has_feature(arg) end
  94. -- Table containing information about a player.
  95. ---@class mt.PlayerInfo
  96. ---@field address string IP address of client
  97. ---@field ip_version integer ip_version
  98. ---@field connection_uptime number seconds since client connected
  99. ---@field protocol_version integer protocol version used by client
  100. ---@field formspec_version integer supported formspec version
  101. ---@field lang_code string Language code used for translation
  102. ---@field min_rtt number|nil minimum round trip time
  103. ---@field max_rtt number|nil maximum round trip time
  104. ---@field avg_rtt number|nil average round trip time
  105. ---@field min_jitter number|nil minimum packet time jitter
  106. ---@field max_jitter number|nil maximum packet time jitter
  107. ---@field avg_jitter number|nil average packet time jitter
  108. ---@field ser_vers number DEBUG ONLY! serialization version used by client
  109. ---@field major number DEBUG ONLY! major version number
  110. ---@field minor number DEBUG ONLY! minor version number
  111. ---@field patch number DEBUG ONLY! patch version number
  112. ---@field vers_string string DEBUG ONLY! full version string
  113. ---@field state string DEBUG ONLY! current client state
  114. ---@param player_name string
  115. ---@return mt.PlayerInfo
  116. function minetest.get_player_information(player_name) end
  117. -- Creates a directory specified by `path`, creating parent directories
  118. -- if they don't exist.
  119. ---@param path string
  120. ---@return boolean success
  121. function minetest.mkdir(path) end
  122. -- Removes a directory specified by `path`.
  123. -- If `recursive` is set to `true`, the directory is recursively removed.
  124. -- Otherwise, the directory will only be removed if it is empty.
  125. ---@param path string
  126. ---@param recursive boolean
  127. ---@return boolean success
  128. function minetest.rmdir(path, recursive) end
  129. -- Copies a directory specified by `path` to `destination`
  130. -- Any files in `destination` will be overwritten if they already exist.
  131. ---@param path string
  132. ---@param destination string
  133. ---@return boolean success
  134. function minetest.cpdir(path, destination) end
  135. -- Moves a directory specified by `path` to `destination`.
  136. -- If the `destination` is a non-empty directory, then the move will fail.
  137. ---@param path string
  138. ---@param destination string
  139. ---@return boolean success
  140. function minetest.mvdir(path, destination) end
  141. -- Returns list of entry names.
  142. ---@param path string
  143. -- * nil: return all entries,
  144. -- * true: return only subdirectory names,
  145. -- * false: return only file names.
  146. ---@param is_dir boolean|nil
  147. ---@return string[]
  148. function minetest.get_dir_list(path, is_dir) end
  149. -- Replaces contents of file at path with new contents in a safe (atomic)
  150. -- way. Use this instead of below code when writing e.g. database files:
  151. -- `local f = io.open(path, "wb"); f:write(content); f:close()`
  152. ---@param path string
  153. ---@param content string
  154. ---@return boolean success
  155. function minetest.safe_file_write(path, content) end
  156. -- Returns a table containing components of the engine version.
  157. ---@return mt.EngineVersion
  158. function minetest.get_version() end
  159. ---@class mt.EngineVersion
  160. ---@field project string Name of the project, eg, "Minetest".
  161. ---@field string string Simple version, eg, "1.2.3-dev".
  162. -- Full git version (only set if available), eg, "1.2.3-dev-01234567-dirty".
  163. ---@field hash string
  164. -- Boolean value indicating whether it's a development build.
  165. -- Use this for informational purposes only. The information in the returned
  166. -- table does not represent the capabilities of the engine, nor is it
  167. -- reliable or verifiable. Compatible forks will have a different name and
  168. -- version entirely. To check for the presence of engine features, test
  169. -- whether the functions exported by the wanted features exist. For example:
  170. -- `if minetest.check_for_falling then ... end`.
  171. ---@field is_dev boolean
  172. -- Returns the sha1 hash of data.
  173. ---@param data string
  174. ---@param raw boolean|nil `false` return raw bytes instead of hex digits
  175. ---@return string
  176. function minetest.sha1(data, raw) end
  177. -- Converts a ColorSpec to a ColorString.
  178. -- If the ColorSpec is invalid, returns `nil`.
  179. ---@param colorspec mt.ColorSpec
  180. ---@return mt.ColorString|nil
  181. function minetest.colorspec_to_colorstring(colorspec) end
  182. -- Converts a ColorSpec to a raw string of four bytes in an RGBA layout.
  183. ---@param colorspec mt.ColorSpec
  184. ---@return string
  185. function minetest.colorspec_to_bytes(colorspec) end
  186. -- Encode a PNG image and return it in string form.
  187. ---@param width integer
  188. ---@param height integer
  189. -- Image data, one of:
  190. -- * array table of ColorSpec, length must be width*height
  191. -- * string with raw RGBA pixels, length must be width*height*4
  192. --
  193. -- The data is one-dimensional, starting in the upper left corner of the image
  194. -- and laid out in scanlines going from left to right, then top to bottom.
  195. -- Please note that it's not safe to use string.char to generate raw data,
  196. -- use `colorspec_to_bytes` to generate raw RGBA values in a predictable way.
  197. -- The resulting PNG image is always 32-bit. Palettes are not supported at the moment.
  198. -- You may use this to procedurally generate textures during server init.
  199. ---@param data mt.ColorSpec[]|string
  200. ---@param compression integer|nil Optional zlib compression level from 0 to 9.
  201. function minetest.encode_png(width, height, data, compression) end