menu_lua_api.txt 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. Minetest Lua Mainmenu API Reference 0.5.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. Favorites:
  121. core.get_favorites(location) -> list of favorites (possible in async calls)
  122. ^ location: "local" or "online"
  123. ^ returns {
  124. [1] = {
  125. clients = <number of clients/nil>,
  126. clients_max = <maximum number of clients/nil>,
  127. version = <server version/nil>,
  128. password = <true/nil>,
  129. creative = <true/nil>,
  130. damage = <true/nil>,
  131. pvp = <true/nil>,
  132. description = <server description/nil>,
  133. name = <server name/nil>,
  134. address = <address of server/nil>,
  135. port = <port>
  136. },
  137. }
  138. core.delete_favorite(id, location) -> success
  139. Logging:
  140. core.debug(line) (possible in async calls)
  141. ^ Always printed to stderr and logfile (print() is redirected here)
  142. core.log(line) (possible in async calls)
  143. core.log(loglevel, line) (possible in async calls)
  144. ^ loglevel one of "error", "action", "info", "verbose"
  145. Settings:
  146. core.setting_set(name, value)
  147. core.setting_get(name) -> string or nil (possible in async calls)
  148. core.setting_setbool(name, value)
  149. core.setting_getbool(name) -> bool or nil (possible in async calls)
  150. core.setting_save() -> nil, save all settings to config file
  151. Worlds:
  152. core.get_worlds() -> list of worlds (possible in async calls)
  153. ^ returns {
  154. [1] = {
  155. path = <full path to world>,
  156. name = <name of world>,
  157. gameid = <gameid of world>,
  158. },
  159. }
  160. core.create_world(worldname, gameid)
  161. core.delete_world(index)
  162. Helpers:
  163. core.get_us_time()
  164. ^ returns time with microsecond precision
  165. core.gettext(string) -> string
  166. ^ look up the translation of a string in the gettext message catalog
  167. fgettext_ne(string, ...)
  168. ^ call core.gettext(string), replace "$1"..."$9" with the given
  169. ^ extra arguments and return the result
  170. fgettext(string, ...) -> string
  171. ^ same as fgettext_ne(), but calls core.formspec_escape before returning result
  172. core.parse_json(string[, nullvalue]) -> something (possible in async calls)
  173. ^ see core.parse_json (lua_api.txt)
  174. dump(obj, dumped={})
  175. ^ Return object serialized as a string
  176. string:split(separator)
  177. ^ eg. string:split("a,b", ",") == {"a","b"}
  178. string:trim()
  179. ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
  180. core.is_yes(arg) (possible in async calls)
  181. ^ returns whether arg can be interpreted as yes
  182. minetest.encode_base64(string) (possible in async calls)
  183. ^ Encodes a string in base64.
  184. minetest.decode_base64(string) (possible in async calls)
  185. ^ Decodes a string encoded in base64.
  186. Version compat:
  187. core.get_min_supp_proto()
  188. ^ returns the minimum supported network protocol version
  189. core.get_max_supp_proto()
  190. ^ returns the maximum supported network protocol version
  191. Async:
  192. core.handle_async(async_job,parameters,finished)
  193. ^ execute a function asynchronously
  194. ^ async_job is a function receiving one parameter and returning one parameter
  195. ^ parameters parameter table passed to async_job
  196. ^ finished function to be called once async_job has finished
  197. ^ the result of async_job is passed to this function
  198. Limitations of Async operations
  199. -No access to global lua variables, don't even try
  200. -Limited set of available functions
  201. e.g. No access to functions modifying menu like core.start,core.close,
  202. core.file_open_dialog
  203. Class reference
  204. ----------------
  205. Settings: see lua_api.txt