1 Minetest Lua Mainmenu API Reference 0.5.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)
70 core.update_formspec(formspec)
71 core.get_table_index(tablename) -> index
72 ^ can also handle textlists
73 core.formspec_escape(string) -> string
74 ^ escapes characters [ ] \ , ; that can not be used in formspecs
75 core.explode_table_event(string) -> table
76 ^ returns e.g. {type="CHG", row=1, column=2}
77 ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
78 core.explode_textlist_event(string) -> table
79 ^ returns e.g. {type="CHG", index=1}
80 ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
83 core.set_background(type, texturepath,[tile],[minsize])
84 ^ type: "background", "overlay", "header" or "footer"
85 ^ tile: tile the image instead of scaling (background only)
86 ^ minsize: minimum tile size, images are scaled to at least this size prior
87 ^ doing tiling (background only)
88 core.set_clouds(<true/false>)
89 core.set_topleft_text(text)
91 core.file_open_dialog(formname,caption)
92 ^ shows a file open dialog
93 ^ formname is base name of dialog response returned in fields
94 ^ -if dialog was accepted "_accepted"
95 ^^ will be added to fieldname containing the path
96 ^ -if dialog was canceled "_cancelled"
97 ^ will be added to fieldname value is set to formname itself
98 ^ returns nil or selected file/folder
99 core.get_screen_info()
101 density = <screen density 0.75,1.0,2.0,3.0 ... (dpi)>,
102 display_width = <width of display>,
103 display_height = <height of display>,
104 window_width = <current window width>,
105 window_height = <current window height>
108 ### Content and Packages
110 Content - an installed mod, modpack, game, or texture pack (txt)
111 Package - content which is downloadable from the content db, may or may not be installed.
113 * core.get_modpath() (possible in async calls)
114 * returns path to global modpath
115 * core.get_clientmodpath() (possible in async calls)
116 * returns path to global client-side modpath
117 * core.get_gamepath() (possible in async calls)
118 * returns path to global gamepath
119 * core.get_texturepath() (possible in async calls)
120 * returns path to default textures
121 * core.get_game(index)
126 path = <full path to game>,
127 gamemods_path = <path>,
128 name = <name of game>,
129 menuicon_path = <full path to menuicon>,
132 addon_mods_paths = {[1] = <path>,},
135 * core.get_games() -> table of all games in upper format (possible in async calls)
136 * core.get_content_info(path)
140 name = "name of content",
141 type = "mod" or "modpack" or "game" or "txp",
142 description = "description",
144 path = "path/to/content",
145 depends = {"mod", "names"}, -- mods only
146 optional_depends = {"mod", "names"}, -- mods only
149 * core.get_package_list() -> downloads package list from content db
154 title = "human readable title",
156 type = "", -- mod, game, txp
157 short_description = "description",
162 core.get_favorites(location) -> list of favorites (possible in async calls)
163 ^ location: "local" or "online"
166 clients = <number of clients/nil>,
167 clients_max = <maximum number of clients/nil>,
168 version = <server version/nil>,
169 password = <true/nil>,
170 creative = <true/nil>,
173 description = <server description/nil>,
174 name = <server name/nil>,
175 address = <address of server/nil>,
179 core.delete_favorite(id, location) -> success
182 core.debug(line) (possible in async calls)
183 ^ Always printed to stderr and logfile (print() is redirected here)
184 core.log(line) (possible in async calls)
185 core.log(loglevel, line) (possible in async calls)
186 ^ loglevel one of "error", "action", "info", "verbose"
189 core.setting_set(name, value)
190 core.setting_get(name) -> string or nil (possible in async calls)
191 core.setting_setbool(name, value)
192 core.setting_getbool(name) -> bool or nil (possible in async calls)
193 core.setting_save() -> nil, save all settings to config file
196 core.get_worlds() -> list of worlds (possible in async calls)
199 path = <full path to world>,
200 name = <name of world>,
201 gameid = <gameid of world>,
204 core.create_world(worldname, gameid)
205 core.delete_world(index)
209 ^ returns time with microsecond precision
210 core.gettext(string) -> string
211 ^ look up the translation of a string in the gettext message catalog
212 fgettext_ne(string, ...)
213 ^ call core.gettext(string), replace "$1"..."$9" with the given
214 ^ extra arguments and return the result
215 fgettext(string, ...) -> string
216 ^ same as fgettext_ne(), but calls core.formspec_escape before returning result
217 core.parse_json(string[, nullvalue]) -> something (possible in async calls)
218 ^ see core.parse_json (lua_api.txt)
220 ^ Return object serialized as a string
221 string:split(separator)
222 ^ eg. string:split("a,b", ",") == {"a","b"}
224 ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
225 core.is_yes(arg) (possible in async calls)
226 ^ returns whether arg can be interpreted as yes
227 minetest.encode_base64(string) (possible in async calls)
228 ^ Encodes a string in base64.
229 minetest.decode_base64(string) (possible in async calls)
230 ^ Decodes a string encoded in base64.
233 core.get_min_supp_proto()
234 ^ returns the minimum supported network protocol version
235 core.get_max_supp_proto()
236 ^ returns the maximum supported network protocol version
239 core.handle_async(async_job,parameters,finished)
240 ^ execute a function asynchronously
241 ^ async_job is a function receiving one parameter and returning one parameter
242 ^ parameters parameter table passed to async_job
243 ^ finished function to be called once async_job has finished
244 ^ the result of async_job is passed to this function
246 Limitations of Async operations
247 -No access to global lua variables, don't even try
248 -Limited set of available functions
249 e.g. No access to functions modifying menu like core.start,core.close,
250 core.file_open_dialog
255 Settings: see lua_api.txt