2
0

menu_lua_api.txt 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. Minetest Lua Mainmenu API Reference 0.4.10
  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. Formspec:
  87. core.update_formspec(formspec)
  88. core.get_table_index(tablename) -> index
  89. ^ can also handle textlists
  90. core.formspec_escape(string) -> string
  91. ^ escapes characters [ ] \ , ; that can not be used in formspecs
  92. core.explode_table_event(string) -> table
  93. ^ returns e.g. {type="CHG", row=1, column=2}
  94. ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
  95. core.explode_textlist_event(string) -> table
  96. ^ returns e.g. {type="CHG", index=1}
  97. ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
  98. GUI:
  99. core.set_background(type, texturepath,[tile],[minsize])
  100. ^ type: "background", "overlay", "header" or "footer"
  101. ^ tile: tile the image instead of scaling (background only)
  102. ^ minsize: minimum tile size, images are scaled to at least this size prior
  103. ^ doing tiling (background only)
  104. core.set_clouds(<true/false>)
  105. core.set_topleft_text(text)
  106. core.show_keys_menu()
  107. core.file_open_dialog(formname,caption)
  108. ^ shows a file open dialog
  109. ^ formname is base name of dialog response returned in fields
  110. ^ -if dialog was accepted "_accepted"
  111. ^^ will be added to fieldname containing the path
  112. ^ -if dialog was canceled "_cancelled"
  113. ^ will be added to fieldname value is set to formname itself
  114. ^ returns nil or selected file/folder
  115. core.get_screen_info()
  116. ^ returns {
  117. density = <screen density 0.75,1.0,2.0,3.0 ... (dpi)>,
  118. display_width = <width of display>,
  119. display_height = <height of display>,
  120. window_width = <current window width>,
  121. window_height = <current window height>
  122. }
  123. Games:
  124. core.get_game(index)
  125. ^ returns {
  126. id = <id>,
  127. path = <full path to game>,
  128. gamemods_path = <path>,
  129. name = <name of game>,
  130. menuicon_path = <full path to menuicon>,
  131. DEPRECATED:
  132. addon_mods_paths = {[1] = <path>,},
  133. }
  134. core.get_games() -> table of all games in upper format (possible in async calls)
  135. Favorites:
  136. core.get_favorites(location) -> list of favorites (possible in async calls)
  137. ^ location: "local" or "online"
  138. ^ returns {
  139. [1] = {
  140. clients = <number of clients/nil>,
  141. clients_max = <maximum number of clients/nil>,
  142. version = <server version/nil>,
  143. password = <true/nil>,
  144. creative = <true/nil>,
  145. damage = <true/nil>,
  146. pvp = <true/nil>,
  147. description = <server description/nil>,
  148. name = <server name/nil>,
  149. address = <address of server/nil>,
  150. port = <port>
  151. },
  152. }
  153. core.delete_favorite(id, location) -> success
  154. Logging:
  155. core.debug(line) (possible in async calls)
  156. ^ Always printed to stderr and logfile (print() is redirected here)
  157. core.log(line) (possible in async calls)
  158. core.log(loglevel, line) (possible in async calls)
  159. ^ loglevel one of "error", "action", "info", "verbose"
  160. Settings:
  161. core.setting_set(name, value)
  162. core.setting_get(name) -> string or nil (possible in async calls)
  163. core.setting_setbool(name, value)
  164. core.setting_getbool(name) -> bool or nil (possible in async calls)
  165. core.setting_save() -> nil, save all settings to config file
  166. Worlds:
  167. core.get_worlds() -> list of worlds (possible in async calls)
  168. ^ returns {
  169. [1] = {
  170. path = <full path to world>,
  171. name = <name of world>,
  172. gameid = <gameid of world>,
  173. },
  174. }
  175. core.create_world(worldname, gameid)
  176. core.delete_world(index)
  177. Helpers:
  178. core.gettext(string) -> string
  179. ^ look up the translation of a string in the gettext message catalog
  180. fgettext(string, ...) -> string
  181. ^ call core.gettext(string), replace "$1"..."$9" with the given
  182. ^ extra arguments, call core.formspec_escape and return the 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. Async:
  194. core.handle_async(async_job,parameters,finished)
  195. ^ execute a function asynchronously
  196. ^ async_job is a function receiving one parameter and returning one parameter
  197. ^ parameters parameter table passed to async_job
  198. ^ finished function to be called once async_job has finished
  199. ^ the result of async_job is passed to this function
  200. Limitations of Async operations
  201. -No access to global lua variables, don't even try
  202. -Limited set of available functions
  203. e.g. No access to functions modifying menu like core.start,core.close,
  204. core.file_open_dialog
  205. Class reference
  206. ----------------
  207. Settings: see lua_api.txt