1 Minetest Lua Mainmenu API Reference 0.4.10
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>,
35 ^ returns directory of script
36 core.get_modpath() (possible in async calls)
37 ^ returns path to global modpath
38 core.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 core.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 core.get_gamepath() (possible in async calls)
59 ^ returns path to global gamepath
60 core.get_texturepath() (possible in async calls)
61 ^ returns path to default textures
62 core.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 core.create_dir(absolute_path) (possible in async calls)
67 ^ absolute_path to directory to create (needs to be absolute)
69 core.delete_dir(absolute_path) (possible in async calls)
70 ^ absolute_path to directory to delete (needs to be absolute)
72 core.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 core.extract_zip(zipfile,destination) [unzip within path required]
79 ^ destination folder to extract to
81 core.download_file(url,target) (possible in async calls)
85 core.get_version() (possible in async calls)
86 ^ returns current core version
87 core.sound_play(spec, looped) -> handle
88 ^ spec = SimpleSoundSpec (see lua-api.txt)
90 core.sound_stop(handle)
93 core.update_formspec(formspec)
94 core.get_table_index(tablename) -> index
95 ^ can also handle textlists
96 core.formspec_escape(string) -> string
97 ^ escapes characters [ ] \ , ; that can not be used in formspecs
98 core.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 core.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 core.set_background(type, texturepath,[tile],[minsize])
107 ^ type: "background", "overlay", "header" or "footer"
108 ^ tile: tile the image instead of scaling (background only)
109 ^ minsize: minimum tile size, images are scaled to at least this size prior
110 ^ doing tiling (background only)
111 core.set_clouds(<true/false>)
112 core.set_topleft_text(text)
113 core.show_keys_menu()
114 core.file_open_dialog(formname,caption)
115 ^ shows a file open dialog
116 ^ formname is base name of dialog response returned in fields
117 ^ -if dialog was accepted "_accepted"
118 ^^ will be added to fieldname containing the path
119 ^ -if dialog was canceled "_cancelled"
120 ^ will be added to fieldname value is set to formname itself
121 ^ returns nil or selected file/folder
122 core.get_screen_info()
124 density = <screen density 0.75,1.0,2.0,3.0 ... (dpi)>,
125 display_width = <width of display>,
126 display_height = <height of display>,
127 window_width = <current window width>,
128 window_height = <current window height>
135 path = <full path to game>,
136 gamemods_path = <path>,
137 name = <name of game>,
138 menuicon_path = <full path to menuicon>,
140 addon_mods_paths = {[1] = <path>,},
142 core.get_games() -> table of all games in upper format (possible in async calls)
145 core.get_favorites(location) -> list of favorites (possible in async calls)
146 ^ location: "local" or "online"
149 clients = <number of clients/nil>,
150 clients_max = <maximum number of clients/nil>,
151 version = <server version/nil>,
152 password = <true/nil>,
153 creative = <true/nil>,
156 description = <server description/nil>,
157 name = <server name/nil>,
158 address = <address of server/nil>,
162 core.delete_favorite(id, location) -> success
165 core.debug(line) (possible in async calls)
166 ^ Always printed to stderr and logfile (print() is redirected here)
167 core.log(line) (possible in async calls)
168 core.log(loglevel, line) (possible in async calls)
169 ^ loglevel one of "error", "action", "info", "verbose"
172 core.setting_set(name, value)
173 core.setting_get(name) -> string or nil (possible in async calls)
174 core.setting_setbool(name, value)
175 core.setting_getbool(name) -> bool or nil (possible in async calls)
176 core.setting_save() -> nil, save all settings to config file
179 core.get_worlds() -> list of worlds (possible in async calls)
182 path = <full path to world>,
183 name = <name of world>,
184 gameid = <gameid of world>,
187 core.create_world(worldname, gameid)
188 core.delete_world(index)
191 core.gettext(string) -> string
192 ^ look up the translation of a string in the gettext message catalog
193 fgettext(string, ...) -> string
194 ^ call core.gettext(string), replace "$1"..."$9" with the given
195 ^ extra arguments, call core.formspec_escape and return the result
196 core.parse_json(string[, nullvalue]) -> something (possible in async calls)
197 ^ see core.parse_json (lua_api.txt)
199 ^ Return object serialized as a string
200 string:split(separator)
201 ^ eg. string:split("a,b", ",") == {"a","b"}
203 ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
204 core.is_yes(arg) (possible in async calls)
205 ^ returns whether arg can be interpreted as yes
208 core.handle_async(async_job,parameters,finished)
209 ^ execute a function asynchronously
210 ^ async_job is a function receiving one parameter and returning one parameter
211 ^ parameters parameter table passed to async_job
212 ^ finished function to be called once async_job has finished
213 ^ the result of async_job is passed to this function
215 Limitations of Async operations
216 -No access to global lua variables, don't even try
217 -Limited set of available functions
218 e.g. No access to functions modifying menu like core.start,core.close,
219 core.file_open_dialog
224 Settings: see lua_api.txt