menu_lua_api.txt 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. Minetest Lua Mainmenu API Reference 0.4.13
  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_modstore_details(modid) (possible in async calls)
  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. core.get_modstore_list() (possible in async calls)
  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. core.get_gamepath() (possible in async calls)
  54. ^ returns path to global gamepath
  55. core.get_texturepath() (possible in async calls)
  56. ^ returns path to default textures
  57. core.create_dir(absolute_path) (possible in async calls)
  58. ^ absolute_path to directory to create (needs to be absolute)
  59. ^ returns true/false
  60. core.delete_dir(absolute_path) (possible in async calls)
  61. ^ absolute_path to directory to delete (needs to be absolute)
  62. ^ returns true/false
  63. core.copy_dir(source,destination,keep_soure) (possible in async calls)
  64. ^ source folder
  65. ^ destination folder
  66. ^ keep_source DEFAULT true --> if set to false source is deleted after copying
  67. ^ returns true/false
  68. core.extract_zip(zipfile,destination) [unzip within path required]
  69. ^ zipfile to extract
  70. ^ destination folder to extract to
  71. ^ returns true/false
  72. core.download_file(url,target) (possible in async calls)
  73. ^ url to download
  74. ^ target to store to
  75. ^ returns true/false
  76. core.get_version() (possible in async calls)
  77. ^ returns current core version
  78. core.sound_play(spec, looped) -> handle
  79. ^ spec = SimpleSoundSpec (see lua-api.txt)
  80. ^ looped = bool
  81. core.sound_stop(handle)
  82. core.get_video_drivers()
  83. ^ get list of video drivers supported by engine (not all modes are guaranteed to work)
  84. ^ returns list of available video drivers' settings name and 'friendly' display name
  85. ^ e.g. { {name="opengl", friendly_name="OpenGL"}, {name="software", friendly_name="Software Renderer"} }
  86. ^ first element of returned list is guaranteed to be the NULL driver
  87. Formspec:
  88. core.update_formspec(formspec)
  89. core.get_table_index(tablename) -> index
  90. ^ can also handle textlists
  91. core.formspec_escape(string) -> string
  92. ^ escapes characters [ ] \ , ; that can not be used in formspecs
  93. core.explode_table_event(string) -> table
  94. ^ returns e.g. {type="CHG", row=1, column=2}
  95. ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
  96. core.explode_textlist_event(string) -> table
  97. ^ returns e.g. {type="CHG", index=1}
  98. ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
  99. GUI:
  100. core.set_background(type, texturepath,[tile],[minsize])
  101. ^ type: "background", "overlay", "header" or "footer"
  102. ^ tile: tile the image instead of scaling (background only)
  103. ^ minsize: minimum tile size, images are scaled to at least this size prior
  104. ^ doing tiling (background only)
  105. core.set_clouds(<true/false>)
  106. core.set_topleft_text(text)
  107. core.show_keys_menu()
  108. core.file_open_dialog(formname,caption)
  109. ^ shows a file open dialog
  110. ^ formname is base name of dialog response returned in fields
  111. ^ -if dialog was accepted "_accepted"
  112. ^^ will be added to fieldname containing the path
  113. ^ -if dialog was canceled "_cancelled"
  114. ^ will be added to fieldname value is set to formname itself
  115. ^ returns nil or selected file/folder
  116. core.get_screen_info()
  117. ^ returns {
  118. density = <screen density 0.75,1.0,2.0,3.0 ... (dpi)>,
  119. display_width = <width of display>,
  120. display_height = <height of display>,
  121. window_width = <current window width>,
  122. window_height = <current window height>
  123. }
  124. Games:
  125. core.get_game(index)
  126. ^ returns {
  127. id = <id>,
  128. path = <full path to game>,
  129. gamemods_path = <path>,
  130. name = <name of game>,
  131. menuicon_path = <full path to menuicon>,
  132. DEPRECATED:
  133. addon_mods_paths = {[1] = <path>,},
  134. }
  135. core.get_games() -> table of all games in upper format (possible in async calls)
  136. core.get_mapgen_names([include_hidden=false]) -> table of map generator algorithms
  137. registered in the core (possible in async calls)
  138. Favorites:
  139. core.get_favorites(location) -> list of favorites (possible in async calls)
  140. ^ location: "local" or "online"
  141. ^ returns {
  142. [1] = {
  143. clients = <number of clients/nil>,
  144. clients_max = <maximum number of clients/nil>,
  145. version = <server version/nil>,
  146. password = <true/nil>,
  147. creative = <true/nil>,
  148. damage = <true/nil>,
  149. pvp = <true/nil>,
  150. description = <server description/nil>,
  151. name = <server name/nil>,
  152. address = <address of server/nil>,
  153. port = <port>
  154. },
  155. }
  156. core.delete_favorite(id, location) -> success
  157. Logging:
  158. core.debug(line) (possible in async calls)
  159. ^ Always printed to stderr and logfile (print() is redirected here)
  160. core.log(line) (possible in async calls)
  161. core.log(loglevel, line) (possible in async calls)
  162. ^ loglevel one of "error", "action", "info", "verbose"
  163. Settings:
  164. core.setting_set(name, value)
  165. core.setting_get(name) -> string or nil (possible in async calls)
  166. core.setting_setbool(name, value)
  167. core.setting_getbool(name) -> bool or nil (possible in async calls)
  168. core.setting_save() -> nil, save all settings to config file
  169. Worlds:
  170. core.get_worlds() -> list of worlds (possible in async calls)
  171. ^ returns {
  172. [1] = {
  173. path = <full path to world>,
  174. name = <name of world>,
  175. gameid = <gameid of world>,
  176. },
  177. }
  178. core.create_world(worldname, gameid)
  179. core.delete_world(index)
  180. Helpers:
  181. core.get_us_time()
  182. ^ returns time with microsecond precision
  183. core.gettext(string) -> string
  184. ^ look up the translation of a string in the gettext message catalog
  185. fgettext_ne(string, ...)
  186. ^ call core.gettext(string), replace "$1"..."$9" with the given
  187. ^ extra arguments and return the result
  188. fgettext(string, ...) -> string
  189. ^ same as fgettext_ne(), but calls core.formspec_escape before returning result
  190. core.parse_json(string[, nullvalue]) -> something (possible in async calls)
  191. ^ see core.parse_json (lua_api.txt)
  192. dump(obj, dumped={})
  193. ^ Return object serialized as a string
  194. string:split(separator)
  195. ^ eg. string:split("a,b", ",") == {"a","b"}
  196. string:trim()
  197. ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
  198. core.is_yes(arg) (possible in async calls)
  199. ^ returns whether arg can be interpreted as yes
  200. Version compat:
  201. core.get_min_supp_proto()
  202. ^ returns the minimum supported network protocol version
  203. core.get_max_supp_proto()
  204. ^ returns the maximum supported network protocol version
  205. Async:
  206. core.handle_async(async_job,parameters,finished)
  207. ^ execute a function asynchronously
  208. ^ async_job is a function receiving one parameter and returning one parameter
  209. ^ parameters parameter table passed to async_job
  210. ^ finished function to be called once async_job has finished
  211. ^ the result of async_job is passed to this function
  212. Limitations of Async operations
  213. -No access to global lua variables, don't even try
  214. -Limited set of available functions
  215. e.g. No access to functions modifying menu like core.start,core.close,
  216. core.file_open_dialog
  217. Class reference
  218. ----------------
  219. Settings: see lua_api.txt