1 Minetest Lua Mainmenu API Reference 5.6.0
2 =========================================
7 The main menu is defined as a formspec by Lua in builtin/mainmenu/
8 Description of formspec language to show your menu is in lua_api.txt
14 core.button_handler(fields): called when a button is pressed.
15 ^ fields = {name1 = value1, name2 = value2, ...}
16 core.event_handler(event)
17 ^ event: "MenuQuit", "KeyEnter", "ExitButton" or "EditBoxEnter"
23 The "gamedata" table is read when calling core.start(). It should contain:
26 password = <password>,
27 address = <IP/adress>,
29 selected_world = <index>, -- 0 for client mode
30 singleplayer = <true/false>,
39 core.get_min_supp_proto()
40 ^ returns the minimum supported network protocol version
41 core.get_max_supp_proto()
42 ^ returns the maximum supported network protocol version
44 ^ opens the URL in a web browser, returns false on failure.
45 ^ Must begin with http:// or https://
47 ^ opens the path in the system file browser/explorer, returns false on failure.
48 ^ Must be an existing directory.
50 ^ Android only. Shares file using the share popup
51 core.get_version() (possible in async calls)
52 ^ returns current core version
59 core.get_builtin_path()
60 ^ returns path to builtin root
61 core.create_dir(absolute_path) (possible in async calls)
62 ^ absolute_path to directory to create (needs to be absolute)
64 core.delete_dir(absolute_path) (possible in async calls)
65 ^ absolute_path to directory to delete (needs to be absolute)
67 core.copy_dir(source,destination,keep_soure) (possible in async calls)
70 ^ keep_source DEFAULT true --> if set to false source is deleted after copying
72 core.is_dir(path) (possible in async calls)
73 ^ returns true if path is a valid dir
74 core.extract_zip(zipfile,destination) [unzip within path required]
76 ^ destination folder to extract to
78 core.sound_play(spec, looped) -> handle
79 ^ spec = SimpleSoundSpec (see lua-api.txt)
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 core.get_mapgen_names([include_hidden=false]) -> table of map generator algorithms
88 registered in the core (possible in async calls)
89 core.get_cache_path() -> path of cache
90 core.get_temp_path([param]) (possible in async calls)
91 ^ param=true: returns path to a temporary file
92 ^ otherwise: returns path to the temporary folder
98 * core.download_file(url, target) (possible in async calls)
99 * url to download, and target to store to
101 * `minetest.get_http_api()` (possible in async calls)
102 * returns `HTTPApiTable` containing http functions.
103 * The returned table contains the functions `fetch_sync`, `fetch_async` and
104 `fetch_async_get` described below.
105 * Function only exists if minetest server was built with cURL support.
106 * `HTTPApiTable.fetch_sync(HTTPRequest req)`: returns HTTPRequestResult
107 * Performs given request synchronously
108 * `HTTPApiTable.fetch_async(HTTPRequest req)`: returns handle
109 * Performs given request asynchronously and returns handle for
110 `HTTPApiTable.fetch_async_get`
111 * `HTTPApiTable.fetch_async_get(handle)`: returns HTTPRequestResult
112 * Return response data for given asynchronous HTTP request
114 ### `HTTPRequest` definition
116 Used by `HTTPApiTable.fetch` and `HTTPApiTable.fetch_async`.
119 url = "http://example.org",
122 -- Timeout for connection in seconds. Default is 3 seconds.
124 post_data = "Raw POST request data string" OR {field1 = "data1", field2 = "data2"},
125 -- Optional, if specified a POST request with post_data is performed.
126 -- Accepts both a string and a table. If a table is specified, encodes
127 -- table as x-www-form-urlencoded key-value pairs.
128 -- If post_data is not specified, a GET request is performed instead.
130 user_agent = "ExampleUserAgent",
131 -- Optional, if specified replaces the default minetest user agent with
134 extra_headers = { "Accept-Language: en-us", "Accept-Charset: utf-8" },
135 -- Optional, if specified adds additional headers to the HTTP request.
136 -- You must make sure that the header strings follow HTTP specification
140 -- Optional, if true performs a multipart HTTP request.
144 ### `HTTPRequestResult` definition
146 Passed to `HTTPApiTable.fetch` callback. Returned by
147 `HTTPApiTable.fetch_async_get`.
151 -- If true, the request has finished (either succeeded, failed or timed
155 -- If true, the request was successful
158 -- If true, the request timed out
170 core.update_formspec(formspec)
171 core.get_table_index(tablename) -> index
172 ^ can also handle textlists
173 core.formspec_escape(string) -> string
174 ^ escapes characters [ ] \ , ; that can not be used in formspecs
175 core.explode_table_event(string) -> table
176 ^ returns e.g. {type="CHG", row=1, column=2}
177 ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
178 core.explode_textlist_event(string) -> table
179 ^ returns e.g. {type="CHG", index=1}
180 ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
181 core.set_formspec_prepend(formspec)
182 ^ string to be added to every mainmenu formspec, to be used for theming.
188 core.set_background(type, texturepath,[tile],[minsize])
189 ^ type: "background", "overlay", "header" or "footer"
190 ^ tile: tile the image instead of scaling (background only)
191 ^ minsize: minimum tile size, images are scaled to at least this size prior
192 ^ doing tiling (background only)
193 core.set_clouds(<true/false>)
194 core.set_topleft_text(text)
195 core.show_keys_menu()
196 core.show_path_select_dialog(formname, caption, is_file_select)
197 ^ shows a path select dialog
198 ^ formname is base name of dialog response returned in fields
199 ^ -if dialog was accepted "_accepted"
200 ^ will be added to fieldname containing the path
201 ^ -if dialog was canceled "_cancelled"
202 ^ will be added to fieldname value is set to formname itself
203 ^ if `is_file_select` is `true`, a file and not a folder will be selected
204 ^ returns nil or selected file/folder
205 core.get_screen_info()
207 density = <screen density 0.75,1.0,2.0,3.0 ... (dpi)>,
208 display_width = <width of display>,
209 display_height = <height of display>,
210 window_width = <current window width>,
211 window_height = <current window height>,
212 render_info = <active render information>
219 Content - an installed mod, modpack, game, or texture pack (txt)
220 Package - content which is downloadable from the content db, may or may not be installed.
222 * core.get_user_path() (possible in async calls)
223 * returns path to global user data,
224 the directory that contains user-provided mods, worlds, games, and texture packs.
225 * core.get_modpath() (possible in async calls)
226 * returns path to global modpath in the user path, where mods can be installed
227 * core.get_modpaths() (possible in async calls)
228 * returns table of virtual path to global modpaths, where mods have been installed
229 The difference with "core.get_modpath" is that no mods should be installed in these
230 directories by Minetest -- they might be read-only.
236 mods = "/home/user/.minetest/mods",
237 share = "/usr/share/minetest/mods",
239 -- Custom dirs can be specified by the MINETEST_MOD_DIR env variable
240 ["/path/to/custom/dir"] = "/path/to/custom/dir",
244 * core.get_clientmodpath() (possible in async calls)
245 * returns path to global client-side modpath
246 * core.get_gamepath() (possible in async calls)
247 * returns path to global gamepath
248 * core.get_texturepath() (possible in async calls)
249 * returns path to default textures
250 * core.get_game(index)
251 * `name` in return value is deprecated, use `title` instead.
256 path = <full path to game>,
257 gamemods_path = <path>,
258 title = <title of game>,
259 menuicon_path = <full path to menuicon>,
262 addon_mods_paths = {[1] = <path>,},
265 * core.get_games() -> table of all games in upper format (possible in async calls)
266 * core.get_content_info(path)
270 name = "technical_id",
271 type = "mod" or "modpack" or "game" or "txp",
272 title = "Human readable title",
273 description = "description",
275 path = "path/to/content",
276 depends = {"mod", "names"}, -- mods only
277 optional_depends = {"mod", "names"}, -- mods only
284 core.debug(line) (possible in async calls)
285 ^ Always printed to stderr and logfile (print() is redirected here)
286 core.log(line) (possible in async calls)
287 core.log(loglevel, line) (possible in async calls)
288 ^ loglevel one of "error", "action", "info", "verbose"
294 core.settings:set(name, value)
295 core.settings:get(name) -> string or nil (possible in async calls)
296 core.settings:set_bool(name, value)
297 core.settings:get_bool(name) -> bool or nil (possible in async calls)
298 core.settings:save() -> nil, save all settings to config file
300 For a complete list of methods of the Settings object see
301 [lua_api.txt](https://github.com/minetest/minetest/blob/master/doc/lua_api.txt)
307 core.get_worlds() -> list of worlds (possible in async calls)
310 path = <full path to world>,
311 name = <name of world>,
312 gameid = <gameid of world>,
315 core.create_world(worldname, gameid)
316 core.delete_world(index)
323 ^ returns time with microsecond precision
324 core.gettext(string) -> string
325 ^ look up the translation of a string in the gettext message catalog
326 fgettext_ne(string, ...)
327 ^ call core.gettext(string), replace "$1"..."$9" with the given
328 ^ extra arguments and return the result
329 fgettext(string, ...) -> string
330 ^ same as fgettext_ne(), but calls core.formspec_escape before returning result
331 core.parse_json(string[, nullvalue]) -> something (possible in async calls)
332 ^ see core.parse_json (lua_api.txt)
334 ^ Return object serialized as a string
335 string:split(separator)
336 ^ eg. string:split("a,b", ",") == {"a","b"}
338 ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
339 core.is_yes(arg) (possible in async calls)
340 ^ returns whether arg can be interpreted as yes
341 minetest.encode_base64(string) (possible in async calls)
342 ^ Encodes a string in base64.
343 minetest.decode_base64(string) (possible in async calls)
344 ^ Decodes a string encoded in base64.
350 core.handle_async(async_job,parameters,finished)
351 ^ execute a function asynchronously
352 ^ async_job is a function receiving one parameter and returning one parameter
353 ^ parameters parameter table passed to async_job
354 ^ finished function to be called once async_job has finished
355 ^ the result of async_job is passed to this function
357 Limitations of Async operations
358 -No access to global lua variables, don't even try
359 -Limited set of available functions
360 e.g. No access to functions modifying menu like core.start,core.close,
361 core.show_path_select_dialog
367 The main menu supports background music.
368 It looks for a `main_menu` sound in `$USER_PATH/sounds`. The same naming
369 conventions as for normal sounds apply.
370 This means the player can add a custom sound.
371 It will be played in the main menu (gain = 1.0), looped.