1 Minetest Lua Mainmenu API Reference 0.4.9
2 ========================================
6 The main menu is defined as a formspec by Lua in builtin/mainmenu.lua
7 Description of formspec language to show your menu is in lua_api.txt
11 engine.buttonhandler(fields): called when a button is pressed.
12 ^ fields = {name1 = value1, name2 = value2, ...}
13 engine.event_handler(event)
14 ^ event: "MenuQuit", "KeyEnter", "ExitButton" or "EditBoxEnter"
18 The "gamedata" table is read when calling engine.start(). It should contain:
21 password = <password>,
22 address = <IP/adress>,
24 selected_world = <index>, -- 0 for client mode
25 singleplayer = <true/false>,
34 engine.get_scriptdir()
35 ^ returns directory of script
36 engine.get_modpath() (possible in async calls)
37 ^ returns path to global modpath
38 engine.get_modstore_details(modid) (possible in async calls)
39 ^ modid numeric id of mod in modstore
41 id = <numeric id of mod in modstore>,
42 title = <human readable title>,
43 basename = <basename for mod>,
44 description = <description of mod>,
45 author = <author of mod>,
46 download_url= <best match download url>,
47 license = <short description of license>,
48 rating = <float value of current rating>
50 engine.get_modstore_list() (possible in async calls)
53 id = <numeric id of mod in modstore>,
54 title = <human readable title>,
55 basename = <basename for mod>
58 engine.get_gamepath() (possible in async calls)
59 ^ returns path to global gamepath
60 engine.get_texturepath() (possible in async calls)
61 ^ returns path to default textures
62 engine.get_dirlist(path,onlydirs) (possible in async calls)
63 ^ path to get subdirs from
64 ^ onlydirs should result contain only dirs?
65 ^ returns list of folders within path
66 engine.create_dir(absolute_path) (possible in async calls)
67 ^ absolute_path to directory to create (needs to be absolute)
69 engine.delete_dir(absolute_path) (possible in async calls)
70 ^ absolute_path to directory to delete (needs to be absolute)
72 engine.copy_dir(source,destination,keep_soure) (possible in async calls)
75 ^ keep_source DEFAULT true --> if set to false source is deleted after copying
77 engine.extract_zip(zipfile,destination) [unzip within path required]
79 ^ destination folder to extract to
81 engine.download_file(url,target) (possible in async calls)
85 engine.get_version() (possible in async calls)
86 ^ returns current minetest version
87 engine.sound_play(spec, looped) -> handle
88 ^ spec = SimpleSoundSpec (see lua-api.txt)
90 engine.sound_stop(handle)
93 engine.update_formspec(formspec)
94 engine.get_table_index(tablename) -> index
95 ^ can also handle textlists
96 engine.formspec_escape(string) -> string
97 ^ escapes characters [ ] \ , ; that can not be used in formspecs
98 engine.explode_table_event(string) -> table
99 ^ returns e.g. {type="CHG", row=1, column=2}
100 ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
101 engine.explode_textlist_event(string) -> table
102 ^ returns e.g. {type="CHG", index=1}
103 ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
106 engine.set_background(type, texturepath)
107 ^ type: "background", "overlay", "header" or "footer"
108 engine.set_clouds(<true/false>)
109 engine.set_topleft_text(text)
110 engine.show_keys_menu()
111 engine.file_open_dialog(formname,caption)
112 ^ shows a file open dialog
113 ^ formname is base name of dialog response returned in fields
114 ^ -if dialog was accepted "_accepted"
115 ^^ will be added to fieldname containing the path
116 ^ -if dialog was canceled "_cancelled"
117 ^ will be added to fieldname value is set to formname itself
118 ^ returns nil or selected file/folder
121 engine.get_game(index)
124 path = <full path to game>,
125 gamemods_path = <path>,
126 name = <name of game>,
127 menuicon_path = <full path to menuicon>,
129 addon_mods_paths = {[1] = <path>,},
131 engine.get_games() -> table of all games in upper format (possible in async calls)
134 engine.get_favorites(location) -> list of favorites (possible in async calls)
135 ^ location: "local" or "online"
138 clients = <number of clients/nil>,
139 clients_max = <maximum number of clients/nil>,
140 version = <server version/nil>,
141 password = <true/nil>,
142 creative = <true/nil>,
145 description = <server description/nil>,
146 name = <server name/nil>,
147 address = <address of server/nil>,
151 engine.delete_favorite(id, location) -> success
154 engine.debug(line) (possible in async calls)
155 ^ Always printed to stderr and logfile (print() is redirected here)
156 engine.log(line) (possible in async calls)
157 engine.log(loglevel, line) (possible in async calls)
158 ^ loglevel one of "error", "action", "info", "verbose"
161 engine.setting_set(name, value)
162 engine.setting_get(name) -> string or nil (possible in async calls)
163 engine.setting_setbool(name, value)
164 engine.setting_getbool(name) -> bool or nil (possible in async calls)
165 engine.setting_save() -> nil, save all settings to config file
168 engine.get_worlds() -> list of worlds (possible in async calls)
171 path = <full path to world>,
172 name = <name of world>,
173 gameid = <gameid of world>,
176 engine.create_world(worldname, gameid)
177 engine.delete_world(index)
180 engine.gettext(string) -> string
181 ^ look up the translation of a string in the gettext message catalog
182 fgettext(string, ...) -> string
183 ^ call engine.gettext(string), replace "$1"..."$9" with the given
184 ^ extra arguments, call engine.formspec_escape and return the result
185 engine.parse_json(string[, nullvalue]) -> something (possible in async calls)
186 ^ see minetest.parse_json (lua_api.txt)
188 ^ Return object serialized as a string
189 string:split(separator)
190 ^ eg. string:split("a,b", ",") == {"a","b"}
192 ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
193 minetest.is_yes(arg) (possible in async calls)
194 ^ returns whether arg can be interpreted as yes
197 engine.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
204 Limitations of Async operations
205 -No access to global lua variables, don't even try
206 -Limited set of available functions
207 e.g. No access to functions modifying menu like engine.start,engine.close,
208 engine.file_open_dialog
213 Settings: see lua_api.txt