1 Minetest Lua Mainmenu API Reference 0.4.6
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
37 ^ returns path to global modpath
38 engine.get_modstore_details(modid)
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()
53 id = <numeric id of mod in modstore>,
54 title = <human readable title>,
55 basename = <basename for mod>
59 ^ returns path to global gamepath
60 engine.get_dirlist(path,onlydirs)
61 ^ path to get subdirs from
62 ^ onlydirs should result contain only dirs?
63 ^ returns list of folders within path
64 engine.create_dir(absolute_path)
65 ^ absolute_path to directory to create (needs to be absolute)
67 engine.delete_dir(absolute_path)
68 ^ absolute_path to directory to delete (needs to be absolute)
70 engine.copy_dir(source,destination,keep_soure)
73 ^ keep_source DEFAULT true --> if set to false source is deleted after copying
75 engine.extract_zip(zipfile,destination) [unzip within path required]
77 ^ destination folder to extract to
79 engine.download_file(url,target)
84 ^ returns current minetest version
85 engine.sound_play(spec, looped) -> handle
86 ^ spec = SimpleSoundSpec (see lua-api.txt)
88 engine.sound_stop(handle)
91 engine.update_formspec(formspec)
92 - engine.set_background(type, texturepath)
93 ^ type: "background", "overlay", "header" or "footer"
94 engine.set_clouds(<true/false>)
95 engine.set_topleft_text(text)
98 engine.get_game(index)
101 path = <full path to game>,
102 gamemods_path = <path>,
103 name = <name of game>,
104 menuicon_path = <full path to menuicon>,
106 addon_mods_paths = {[1] = <path>,},
108 engine.get_games() -> table of all games in upper format
111 engine.get_favorites(location) -> list of favorites
112 ^ location: "local" or "online"
115 clients = <number of clients/nil>,
116 clients_max = <maximum number of clients/nil>,
117 version = <server version/nil>,
118 password = <true/nil>,
119 creative = <true/nil>,
122 description = <server description/nil>,
123 name = <server name/nil>,
124 address = <address of server/nil>,
128 engine.delete_favorite(id, location) -> success
132 ^ Always printed to stderr and logfile (print() is redirected here)
134 engine.log(loglevel, line)
135 ^ loglevel one of "error", "action", "info", "verbose"
138 engine.setting_set(name, value)
139 engine.setting_get(name) -> string or nil
140 engine.setting_setbool(name, value)
141 engine.setting_getbool(name) -> bool or nil
142 engine.setting_save() -> nil, save all settings to config file
145 engine.get_worlds() -> list of worlds
148 path = <full path to world>,
149 name = <name of world>,
150 gameid = <gameid of world>,
153 engine.create_world(worldname, gameid)
154 engine.delete_world(index)
158 engine.get_textlist_index(textlistname) -> index
159 engine.show_keys_menu()
160 engine.file_open_dialog(formname,caption)
161 ^ shows a file open dialog
162 ^ formname is base name of dialog response returned in fields
163 ^ -if dialog was accepted "_accepted"
164 ^^ will be added to fieldname containing the path
165 ^ -if dialog was canceled "_cancelled"
166 ^ will be added to fieldname value is set to formname itself
167 ^ returns nil or selected file/folder
170 engine.formspec_escape(string) -> string
171 ^ escapes characters [ ] \ , ; that can not be used in formspecs
172 engine.gettext(string) -> string
173 ^ look up the translation of a string in the gettext message catalog
174 fgettext(string, ...) -> string
175 ^ call engine.gettext(string), replace "$1"..."$9" with the given
176 ^ extra arguments, call engine.formspec_escape and return the result
177 engine.parse_json(string[, nullvalue]) -> something
178 ^ see minetest.parse_json (lua_api.txt)
180 ^ Return object serialized as a string
181 string:split(separator)
182 ^ eg. string:split("a,b", ",") == {"a","b"}
184 ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
186 ^ returns whether arg can be interpreted as yes
190 Settings: see lua_api.txt