1 Minetest Lua Mainmenu API Reference 5.0.0
2 =========================================
6 The main menu is defined as a formspec by Lua in builtin/mainmenu/
7 Description of formspec language to show your menu is in lua_api.txt
11 core.buttonhandler(fields): called when a button is pressed.
12 ^ fields = {name1 = value1, name2 = value2, ...}
13 core.event_handler(event)
14 ^ event: "MenuQuit", "KeyEnter", "ExitButton" or "EditBoxEnter"
18 The "gamedata" table is read when calling core.start(). It should contain:
21 password = <password>,
22 address = <IP/adress>,
24 selected_world = <index>, -- 0 for client mode
25 singleplayer = <true/false>,
34 core.get_builtin_path()
35 ^ returns path to builtin root
36 core.create_dir(absolute_path) (possible in async calls)
37 ^ absolute_path to directory to create (needs to be absolute)
39 core.delete_dir(absolute_path) (possible in async calls)
40 ^ absolute_path to directory to delete (needs to be absolute)
42 core.copy_dir(source,destination,keep_soure) (possible in async calls)
45 ^ keep_source DEFAULT true --> if set to false source is deleted after copying
47 core.extract_zip(zipfile,destination) [unzip within path required]
49 ^ destination folder to extract to
51 core.download_file(url,target) (possible in async calls)
55 core.get_version() (possible in async calls)
56 ^ returns current core version
57 core.sound_play(spec, looped) -> handle
58 ^ spec = SimpleSoundSpec (see lua-api.txt)
60 core.sound_stop(handle)
61 core.get_video_drivers()
62 ^ get list of video drivers supported by engine (not all modes are guaranteed to work)
63 ^ returns list of available video drivers' settings name and 'friendly' display name
64 ^ e.g. { {name="opengl", friendly_name="OpenGL"}, {name="software", friendly_name="Software Renderer"} }
65 ^ first element of returned list is guaranteed to be the NULL driver
66 core.get_mapgen_names([include_hidden=false]) -> table of map generator algorithms
67 registered in the core (possible in async calls)
68 core.get_cache_path() -> path of cache
71 core.update_formspec(formspec)
72 core.get_table_index(tablename) -> index
73 ^ can also handle textlists
74 core.formspec_escape(string) -> string
75 ^ escapes characters [ ] \ , ; that can not be used in formspecs
76 core.explode_table_event(string) -> table
77 ^ returns e.g. {type="CHG", row=1, column=2}
78 ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
79 core.explode_textlist_event(string) -> table
80 ^ returns e.g. {type="CHG", index=1}
81 ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
84 core.set_background(type, texturepath,[tile],[minsize])
85 ^ type: "background", "overlay", "header" or "footer"
86 ^ tile: tile the image instead of scaling (background only)
87 ^ minsize: minimum tile size, images are scaled to at least this size prior
88 ^ doing tiling (background only)
89 core.set_clouds(<true/false>)
90 core.set_topleft_text(text)
92 core.file_open_dialog(formname,caption)
93 ^ shows a file open dialog
94 ^ formname is base name of dialog response returned in fields
95 ^ -if dialog was accepted "_accepted"
96 ^^ will be added to fieldname containing the path
97 ^ -if dialog was canceled "_cancelled"
98 ^ will be added to fieldname value is set to formname itself
99 ^ returns nil or selected file/folder
100 core.get_screen_info()
102 density = <screen density 0.75,1.0,2.0,3.0 ... (dpi)>,
103 display_width = <width of display>,
104 display_height = <height of display>,
105 window_width = <current window width>,
106 window_height = <current window height>
109 ### Content and Packages
111 Content - an installed mod, modpack, game, or texture pack (txt)
112 Package - content which is downloadable from the content db, may or may not be installed.
114 * core.get_modpath() (possible in async calls)
115 * returns path to global modpath
116 * core.get_clientmodpath() (possible in async calls)
117 * returns path to global client-side modpath
118 * core.get_gamepath() (possible in async calls)
119 * returns path to global gamepath
120 * core.get_texturepath() (possible in async calls)
121 * returns path to default textures
122 * core.get_game(index)
127 path = <full path to game>,
128 gamemods_path = <path>,
129 name = <name of game>,
130 menuicon_path = <full path to menuicon>,
133 addon_mods_paths = {[1] = <path>,},
136 * core.get_games() -> table of all games in upper format (possible in async calls)
137 * core.get_content_info(path)
141 name = "name of content",
142 type = "mod" or "modpack" or "game" or "txp",
143 description = "description",
145 path = "path/to/content",
146 depends = {"mod", "names"}, -- mods only
147 optional_depends = {"mod", "names"}, -- mods only
152 core.get_favorites(location) -> list of favorites (possible in async calls)
153 ^ location: "local" or "online"
156 clients = <number of clients/nil>,
157 clients_max = <maximum number of clients/nil>,
158 version = <server version/nil>,
159 password = <true/nil>,
160 creative = <true/nil>,
163 description = <server description/nil>,
164 name = <server name/nil>,
165 address = <address of server/nil>,
169 core.delete_favorite(id, location) -> success
172 core.debug(line) (possible in async calls)
173 ^ Always printed to stderr and logfile (print() is redirected here)
174 core.log(line) (possible in async calls)
175 core.log(loglevel, line) (possible in async calls)
176 ^ loglevel one of "error", "action", "info", "verbose"
179 core.settings:set(name, value)
180 core.settings:get(name) -> string or nil (possible in async calls)
181 core.settings:set_bool(name, value)
182 core.settings:get_bool(name) -> bool or nil (possible in async calls)
183 core.settings:save() -> nil, save all settings to config file
185 For a complete list of methods of the Settings object see
186 [lua_api.txt](https://github.com/minetest/minetest/blob/master/doc/lua_api.txt)
189 core.get_worlds() -> list of worlds (possible in async calls)
192 path = <full path to world>,
193 name = <name of world>,
194 gameid = <gameid of world>,
197 core.create_world(worldname, gameid)
198 core.delete_world(index)
202 ^ returns time with microsecond precision
203 core.gettext(string) -> string
204 ^ look up the translation of a string in the gettext message catalog
205 fgettext_ne(string, ...)
206 ^ call core.gettext(string), replace "$1"..."$9" with the given
207 ^ extra arguments and return the result
208 fgettext(string, ...) -> string
209 ^ same as fgettext_ne(), but calls core.formspec_escape before returning result
210 core.parse_json(string[, nullvalue]) -> something (possible in async calls)
211 ^ see core.parse_json (lua_api.txt)
213 ^ Return object serialized as a string
214 string:split(separator)
215 ^ eg. string:split("a,b", ",") == {"a","b"}
217 ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
218 core.is_yes(arg) (possible in async calls)
219 ^ returns whether arg can be interpreted as yes
220 minetest.encode_base64(string) (possible in async calls)
221 ^ Encodes a string in base64.
222 minetest.decode_base64(string) (possible in async calls)
223 ^ Decodes a string encoded in base64.
226 core.get_min_supp_proto()
227 ^ returns the minimum supported network protocol version
228 core.get_max_supp_proto()
229 ^ returns the maximum supported network protocol version
232 core.handle_async(async_job,parameters,finished)
233 ^ execute a function asynchronously
234 ^ async_job is a function receiving one parameter and returning one parameter
235 ^ parameters parameter table passed to async_job
236 ^ finished function to be called once async_job has finished
237 ^ the result of async_job is passed to this function
239 Limitations of Async operations
240 -No access to global lua variables, don't even try
241 -Limited set of available functions
242 e.g. No access to functions modifying menu like core.start,core.close,
243 core.file_open_dialog