menu_lua_api.txt 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. Minetest Lua Mainmenu API Reference 0.4.6
  2. ========================================
  3. Introduction
  4. -------------
  5. The main menu is defined as a formspec by Lua in builtin/mainmenu.lua
  6. Description of formspec language to show your menu is in lua_api.txt
  7. Callbacks
  8. ---------
  9. engine.buttonhandler(fields): called when a button is pressed.
  10. ^ fields = {name1 = value1, name2 = value2, ...}
  11. engine.event_handler(event)
  12. ^ event: "MenuQuit", "KeyEnter", "ExitButton" or "EditBoxEnter"
  13. Gamedata
  14. --------
  15. The "gamedata" table is read when calling engine.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. engine.start()
  27. engine.close()
  28. Filesystem:
  29. engine.get_scriptdir()
  30. ^ returns directory of script
  31. engine.get_modpath()
  32. ^ returns path to global modpath
  33. engine.get_modstore_details(modid)
  34. ^ modid numeric id of mod in modstore
  35. ^ returns {
  36. id = <numeric id of mod in modstore>,
  37. title = <human readable title>,
  38. basename = <basename for mod>,
  39. description = <description of mod>,
  40. author = <author of mod>,
  41. download_url= <best match download url>,
  42. license = <short description of license>,
  43. rating = <float value of current rating>
  44. }
  45. engine.get_modstore_list()
  46. ^ returns {
  47. [1] = {
  48. id = <numeric id of mod in modstore>,
  49. title = <human readable title>,
  50. basename = <basename for mod>
  51. }
  52. }
  53. engine.get_gamepath()
  54. ^ returns path to global gamepath
  55. engine.get_dirlist(path,onlydirs)
  56. ^ path to get subdirs from
  57. ^ onlydirs should result contain only dirs?
  58. ^ returns list of folders within path
  59. engine.create_dir(absolute_path)
  60. ^ absolute_path to directory to create (needs to be absolute)
  61. ^ returns true/false
  62. engine.delete_dir(absolute_path)
  63. ^ absolute_path to directory to delete (needs to be absolute)
  64. ^ returns true/false
  65. engine.copy_dir(source,destination,keep_soure)
  66. ^ source folder
  67. ^ destination folder
  68. ^ keep_source DEFAULT true --> if set to false source is deleted after copying
  69. ^ returns true/false
  70. engine.extract_zip(zipfile,destination) [unzip within path required]
  71. ^ zipfile to extract
  72. ^ destination folder to extract to
  73. ^ returns true/false
  74. engine.download_file(url,target)
  75. ^ url to download
  76. ^ target to store to
  77. ^ returns true/false
  78. engine.get_version()
  79. ^ returns current minetest version
  80. engine.sound_play(spec, looped) -> handle
  81. ^ spec = SimpleSoundSpec (see lua-api.txt)
  82. ^ looped = bool
  83. engine.sound_stop(handle)
  84. GUI:
  85. engine.update_formspec(formspec)
  86. - engine.set_background(type, texturepath)
  87. ^ type: "background", "overlay", "header" or "footer"
  88. engine.set_clouds(<true/false>)
  89. engine.set_topleft_text(text)
  90. Games:
  91. engine.get_game(index)
  92. ^ returns {
  93. id = <id>,
  94. path = <full path to game>,
  95. gamemods_path = <path>,
  96. name = <name of game>,
  97. menuicon_path = <full path to menuicon>,
  98. DEPRECATED:
  99. addon_mods_paths = {[1] = <path>,},
  100. }
  101. engine.get_games() -> table of all games in upper format
  102. Favorites:
  103. engine.get_favorites(location) -> list of favorites
  104. ^ location: "local" or "online"
  105. ^ returns {
  106. [1] = {
  107. clients = <number of clients/nil>,
  108. clients_max = <maximum number of clients/nil>,
  109. version = <server version/nil>,
  110. password = <true/nil>,
  111. creative = <true/nil>,
  112. damage = <true/nil>,
  113. pvp = <true/nil>,
  114. description = <server description/nil>,
  115. name = <server name/nil>,
  116. address = <address of server/nil>,
  117. port = <port>
  118. },
  119. }
  120. engine.delete_favorite(id, location) -> success
  121. Logging:
  122. engine.debug(line)
  123. ^ Always printed to stderr and logfile (print() is redirected here)
  124. engine.log(line)
  125. engine.log(loglevel, line)
  126. ^ loglevel one of "error", "action", "info", "verbose"
  127. Settings:
  128. engine.setting_set(name, value)
  129. engine.setting_get(name) -> string or nil
  130. engine.setting_setbool(name, value)
  131. engine.setting_getbool(name) -> bool or nil
  132. engine.setting_save() -> nil, save all settings to config file
  133. Worlds:
  134. engine.get_worlds() -> list of worlds
  135. ^ returns {
  136. [1] = {
  137. path = <full path to world>,
  138. name = <name of world>,
  139. gameid = <gameid of world>,
  140. },
  141. }
  142. engine.create_world(worldname, gameid)
  143. engine.delete_world(index)
  144. UI:
  145. engine.get_textlist_index(textlistname) -> index
  146. engine.show_keys_menu()
  147. engine.file_open_dialog(formname,caption)
  148. ^ shows a file open dialog
  149. ^ formname is base name of dialog response returned in fields
  150. ^ -if dialog was accepted "_accepted"
  151. ^^ will be added to fieldname containing the path
  152. ^ -if dialog was canceled "_cancelled"
  153. ^ will be added to fieldname value is set to formname itself
  154. ^ returns nil or selected file/folder
  155. Helpers:
  156. engine.formspec_escape(string) -> string
  157. ^ escapes characters [ ] \ , ; that can not be used in formspecs
  158. engine.gettext(string) -> string
  159. ^ look up the translation of a string in the gettext message catalog
  160. fgettext(string, ...) -> string
  161. ^ call engine.gettext(string), replace "$1"..."$9" with the given
  162. ^ extra arguments, call engine.formspec_escape and return the result
  163. engine.parse_json(string[, nullvalue]) -> something
  164. ^ see minetest.parse_json (lua_api.txt)
  165. dump(obj, dumped={})
  166. ^ Return object serialized as a string
  167. string:split(separator)
  168. ^ eg. string:split("a,b", ",") == {"a","b"}
  169. string:trim()
  170. ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
  171. minetest.is_yes(arg)
  172. ^ returns whether arg can be interpreted as yes
  173. Class reference
  174. ----------------
  175. Settings: see lua_api.txt