menu_lua_api.txt 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. Minetest Lua Mainmenu API Reference 0.4.11
  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_scriptdir()
  30. ^ returns directory of script
  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.get_dirlist(path,onlydirs) (possible in async calls)
  58. ^ path to get subdirs from
  59. ^ onlydirs should result contain only dirs?
  60. ^ returns list of folders within path
  61. core.create_dir(absolute_path) (possible in async calls)
  62. ^ absolute_path to directory to create (needs to be absolute)
  63. ^ returns true/false
  64. core.delete_dir(absolute_path) (possible in async calls)
  65. ^ absolute_path to directory to delete (needs to be absolute)
  66. ^ returns true/false
  67. core.copy_dir(source,destination,keep_soure) (possible in async calls)
  68. ^ source folder
  69. ^ destination folder
  70. ^ keep_source DEFAULT true --> if set to false source is deleted after copying
  71. ^ returns true/false
  72. core.extract_zip(zipfile,destination) [unzip within path required]
  73. ^ zipfile to extract
  74. ^ destination folder to extract to
  75. ^ returns true/false
  76. core.download_file(url,target) (possible in async calls)
  77. ^ url to download
  78. ^ target to store to
  79. ^ returns true/false
  80. core.get_version() (possible in async calls)
  81. ^ returns current core version
  82. core.sound_play(spec, looped) -> handle
  83. ^ spec = SimpleSoundSpec (see lua-api.txt)
  84. ^ looped = bool
  85. core.sound_stop(handle)
  86. core.get_video_drivers()
  87. ^ get list of video drivers supported by engine (not all modes are guaranteed to work)
  88. ^ returns list of available video drivers e.g. { "OpenGL", "Software" }
  89. Formspec:
  90. core.update_formspec(formspec)
  91. core.get_table_index(tablename) -> index
  92. ^ can also handle textlists
  93. core.formspec_escape(string) -> string
  94. ^ escapes characters [ ] \ , ; that can not be used in formspecs
  95. core.explode_table_event(string) -> table
  96. ^ returns e.g. {type="CHG", row=1, column=2}
  97. ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
  98. core.explode_textlist_event(string) -> table
  99. ^ returns e.g. {type="CHG", index=1}
  100. ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
  101. GUI:
  102. core.set_background(type, texturepath,[tile],[minsize])
  103. ^ type: "background", "overlay", "header" or "footer"
  104. ^ tile: tile the image instead of scaling (background only)
  105. ^ minsize: minimum tile size, images are scaled to at least this size prior
  106. ^ doing tiling (background only)
  107. core.set_clouds(<true/false>)
  108. core.set_topleft_text(text)
  109. core.show_keys_menu()
  110. core.file_open_dialog(formname,caption)
  111. ^ shows a file open dialog
  112. ^ formname is base name of dialog response returned in fields
  113. ^ -if dialog was accepted "_accepted"
  114. ^^ will be added to fieldname containing the path
  115. ^ -if dialog was canceled "_cancelled"
  116. ^ will be added to fieldname value is set to formname itself
  117. ^ returns nil or selected file/folder
  118. core.get_screen_info()
  119. ^ returns {
  120. density = <screen density 0.75,1.0,2.0,3.0 ... (dpi)>,
  121. display_width = <width of display>,
  122. display_height = <height of display>,
  123. window_width = <current window width>,
  124. window_height = <current window height>
  125. }
  126. Games:
  127. core.get_game(index)
  128. ^ returns {
  129. id = <id>,
  130. path = <full path to game>,
  131. gamemods_path = <path>,
  132. name = <name of game>,
  133. menuicon_path = <full path to menuicon>,
  134. DEPRECATED:
  135. addon_mods_paths = {[1] = <path>,},
  136. }
  137. core.get_games() -> table of all games in upper format (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.gettext(string) -> string
  182. ^ look up the translation of a string in the gettext message catalog
  183. fgettext(string, ...) -> string
  184. ^ call core.gettext(string), replace "$1"..."$9" with the given
  185. ^ extra arguments, call core.formspec_escape and return the result
  186. core.parse_json(string[, nullvalue]) -> something (possible in async calls)
  187. ^ see core.parse_json (lua_api.txt)
  188. dump(obj, dumped={})
  189. ^ Return object serialized as a string
  190. string:split(separator)
  191. ^ eg. string:split("a,b", ",") == {"a","b"}
  192. string:trim()
  193. ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
  194. core.is_yes(arg) (possible in async calls)
  195. ^ returns whether arg can be interpreted as yes
  196. Async:
  197. core.handle_async(async_job,parameters,finished)
  198. ^ execute a function asynchronously
  199. ^ async_job is a function receiving one parameter and returning one parameter
  200. ^ parameters parameter table passed to async_job
  201. ^ finished function to be called once async_job has finished
  202. ^ the result of async_job is passed to this function
  203. Limitations of Async operations
  204. -No access to global lua variables, don't even try
  205. -Limited set of available functions
  206. e.g. No access to functions modifying menu like core.start,core.close,
  207. core.file_open_dialog
  208. Class reference
  209. ----------------
  210. Settings: see lua_api.txt