You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

231 lines
8.0 KiB

  1. Minetest Lua Mainmenu API Reference 5.0.0
  2. =========================================
  3. Introduction
  4. -------------
  5. The main menu is defined as a formspec by Lua in builtin/mainmenu/
  6. Description of formspec language to show your menu is in lua_api.txt
  7. Callbacks
  8. ---------
  9. core.buttonhandler(fields): called when a button is pressed.
  10. ^ fields = {name1 = value1, name2 = value2, ...}
  11. core.event_handler(event)
  12. ^ event: "MenuQuit", "KeyEnter", "ExitButton" or "EditBoxEnter"
  13. Gamedata
  14. --------
  15. The "gamedata" table is read when calling core.start(). It should contain:
  16. {
  17. playername = <name>,
  18. password = <password>,
  19. address = <IP/adress>,
  20. port = <port>,
  21. selected_world = <index>, -- 0 for client mode
  22. singleplayer = <true/false>,
  23. }
  24. Functions
  25. ---------
  26. core.start()
  27. core.close()
  28. Filesystem:
  29. core.get_builtin_path()
  30. ^ returns path to builtin root
  31. core.get_modpath() (possible in async calls)
  32. ^ returns path to global modpath
  33. core.get_clientmodpath() (possible in async calls)
  34. ^ returns path to global client-side modpath
  35. core.get_gamepath() (possible in async calls)
  36. ^ returns path to global gamepath
  37. core.get_texturepath() (possible in async calls)
  38. ^ returns path to default textures
  39. core.create_dir(absolute_path) (possible in async calls)
  40. ^ absolute_path to directory to create (needs to be absolute)
  41. ^ returns true/false
  42. core.delete_dir(absolute_path) (possible in async calls)
  43. ^ absolute_path to directory to delete (needs to be absolute)
  44. ^ returns true/false
  45. core.copy_dir(source,destination,keep_soure) (possible in async calls)
  46. ^ source folder
  47. ^ destination folder
  48. ^ keep_source DEFAULT true --> if set to false source is deleted after copying
  49. ^ returns true/false
  50. core.extract_zip(zipfile,destination) [unzip within path required]
  51. ^ zipfile to extract
  52. ^ destination folder to extract to
  53. ^ returns true/false
  54. core.download_file(url,target) (possible in async calls)
  55. ^ url to download
  56. ^ target to store to
  57. ^ returns true/false
  58. core.get_version() (possible in async calls)
  59. ^ returns current core version
  60. core.sound_play(spec, looped) -> handle
  61. ^ spec = SimpleSoundSpec (see lua-api.txt)
  62. ^ looped = bool
  63. core.sound_stop(handle)
  64. core.get_video_drivers()
  65. ^ get list of video drivers supported by engine (not all modes are guaranteed to work)
  66. ^ returns list of available video drivers' settings name and 'friendly' display name
  67. ^ e.g. { {name="opengl", friendly_name="OpenGL"}, {name="software", friendly_name="Software Renderer"} }
  68. ^ first element of returned list is guaranteed to be the NULL driver
  69. Formspec:
  70. core.update_formspec(formspec)
  71. core.get_table_index(tablename) -> index
  72. ^ can also handle textlists
  73. core.formspec_escape(string) -> string
  74. ^ escapes characters [ ] \ , ; that can not be used in formspecs
  75. core.explode_table_event(string) -> table
  76. ^ returns e.g. {type="CHG", row=1, column=2}
  77. ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
  78. core.explode_textlist_event(string) -> table
  79. ^ returns e.g. {type="CHG", index=1}
  80. ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
  81. GUI:
  82. core.set_background(type, texturepath,[tile],[minsize])
  83. ^ type: "background", "overlay", "header" or "footer"
  84. ^ tile: tile the image instead of scaling (background only)
  85. ^ minsize: minimum tile size, images are scaled to at least this size prior
  86. ^ doing tiling (background only)
  87. core.set_clouds(<true/false>)
  88. core.set_topleft_text(text)
  89. core.show_keys_menu()
  90. core.file_open_dialog(formname,caption)
  91. ^ shows a file open dialog
  92. ^ formname is base name of dialog response returned in fields
  93. ^ -if dialog was accepted "_accepted"
  94. ^^ will be added to fieldname containing the path
  95. ^ -if dialog was canceled "_cancelled"
  96. ^ will be added to fieldname value is set to formname itself
  97. ^ returns nil or selected file/folder
  98. core.get_screen_info()
  99. ^ returns {
  100. density = <screen density 0.75,1.0,2.0,3.0 ... (dpi)>,
  101. display_width = <width of display>,
  102. display_height = <height of display>,
  103. window_width = <current window width>,
  104. window_height = <current window height>
  105. }
  106. Games:
  107. core.get_game(index)
  108. ^ returns {
  109. id = <id>,
  110. path = <full path to game>,
  111. gamemods_path = <path>,
  112. name = <name of game>,
  113. menuicon_path = <full path to menuicon>,
  114. DEPRECATED:
  115. addon_mods_paths = {[1] = <path>,},
  116. }
  117. core.get_games() -> table of all games in upper format (possible in async calls)
  118. core.get_mapgen_names([include_hidden=false]) -> table of map generator algorithms
  119. registered in the core (possible in async calls)
  120. core.get_mod_info(path)
  121. ^ returns {
  122. name = "name of mod",
  123. type = "mod" or "modpack",
  124. description = "description",
  125. path = "path/to/mod",
  126. depends = {"mod", "names"},
  127. optional_depends = {"mod", "names"},
  128. }
  129. Favorites:
  130. core.get_favorites(location) -> list of favorites (possible in async calls)
  131. ^ location: "local" or "online"
  132. ^ returns {
  133. [1] = {
  134. clients = <number of clients/nil>,
  135. clients_max = <maximum number of clients/nil>,
  136. version = <server version/nil>,
  137. password = <true/nil>,
  138. creative = <true/nil>,
  139. damage = <true/nil>,
  140. pvp = <true/nil>,
  141. description = <server description/nil>,
  142. name = <server name/nil>,
  143. address = <address of server/nil>,
  144. port = <port>
  145. },
  146. }
  147. core.delete_favorite(id, location) -> success
  148. Logging:
  149. core.debug(line) (possible in async calls)
  150. ^ Always printed to stderr and logfile (print() is redirected here)
  151. core.log(line) (possible in async calls)
  152. core.log(loglevel, line) (possible in async calls)
  153. ^ loglevel one of "error", "action", "info", "verbose"
  154. Settings:
  155. core.settings:set(name, value)
  156. core.settings:get(name) -> string or nil (possible in async calls)
  157. core.settings:set_bool(name, value)
  158. core.settings:get_bool(name) -> bool or nil (possible in async calls)
  159. core.settings:save() -> nil, save all settings to config file
  160. For a complete list of methods of the Settings object see
  161. [lua_api.txt](https://github.com/minetest/minetest/blob/master/doc/lua_api.txt)
  162. Worlds:
  163. core.get_worlds() -> list of worlds (possible in async calls)
  164. ^ returns {
  165. [1] = {
  166. path = <full path to world>,
  167. name = <name of world>,
  168. gameid = <gameid of world>,
  169. },
  170. }
  171. core.create_world(worldname, gameid)
  172. core.delete_world(index)
  173. Helpers:
  174. core.get_us_time()
  175. ^ returns time with microsecond precision
  176. core.gettext(string) -> string
  177. ^ look up the translation of a string in the gettext message catalog
  178. fgettext_ne(string, ...)
  179. ^ call core.gettext(string), replace "$1"..."$9" with the given
  180. ^ extra arguments and return the result
  181. fgettext(string, ...) -> string
  182. ^ same as fgettext_ne(), but calls core.formspec_escape before returning result
  183. core.parse_json(string[, nullvalue]) -> something (possible in async calls)
  184. ^ see core.parse_json (lua_api.txt)
  185. dump(obj, dumped={})
  186. ^ Return object serialized as a string
  187. string:split(separator)
  188. ^ eg. string:split("a,b", ",") == {"a","b"}
  189. string:trim()
  190. ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
  191. core.is_yes(arg) (possible in async calls)
  192. ^ returns whether arg can be interpreted as yes
  193. minetest.encode_base64(string) (possible in async calls)
  194. ^ Encodes a string in base64.
  195. minetest.decode_base64(string) (possible in async calls)
  196. ^ Decodes a string encoded in base64.
  197. Version compat:
  198. core.get_min_supp_proto()
  199. ^ returns the minimum supported network protocol version
  200. core.get_max_supp_proto()
  201. ^ returns the maximum supported network protocol version
  202. Async:
  203. core.handle_async(async_job,parameters,finished)
  204. ^ execute a function asynchronously
  205. ^ async_job is a function receiving one parameter and returning one parameter
  206. ^ parameters parameter table passed to async_job
  207. ^ finished function to be called once async_job has finished
  208. ^ the result of async_job is passed to this function
  209. Limitations of Async operations
  210. -No access to global lua variables, don't even try
  211. -Limited set of available functions
  212. e.g. No access to functions modifying menu like core.start,core.close,
  213. core.file_open_dialog