1 Minetest Lua Mainmenu API Reference 0.4.11
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)
91 core.get_video_drivers()
92 ^ get list of video drivers supported by engine (not all modes are guaranteed to work)
93 ^ returns list of available video drivers' settings name and 'friendly' display name
94 ^ e.g. { {name="opengl", friendly_name="OpenGL"}, {name="software", friendly_name="Software Renderer"} }
95 ^ first element of returned list is guaranteed to be the NULL driver
98 core.update_formspec(formspec)
99 core.get_table_index(tablename) -> index
100 ^ can also handle textlists
101 core.formspec_escape(string) -> string
102 ^ escapes characters [ ] \ , ; that can not be used in formspecs
103 core.explode_table_event(string) -> table
104 ^ returns e.g. {type="CHG", row=1, column=2}
105 ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
106 core.explode_textlist_event(string) -> table
107 ^ returns e.g. {type="CHG", index=1}
108 ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
111 core.set_background(type, texturepath,[tile],[minsize])
112 ^ type: "background", "overlay", "header" or "footer"
113 ^ tile: tile the image instead of scaling (background only)
114 ^ minsize: minimum tile size, images are scaled to at least this size prior
115 ^ doing tiling (background only)
116 core.set_clouds(<true/false>)
117 core.set_topleft_text(text)
118 core.show_keys_menu()
119 core.file_open_dialog(formname,caption)
120 ^ shows a file open dialog
121 ^ formname is base name of dialog response returned in fields
122 ^ -if dialog was accepted "_accepted"
123 ^^ will be added to fieldname containing the path
124 ^ -if dialog was canceled "_cancelled"
125 ^ will be added to fieldname value is set to formname itself
126 ^ returns nil or selected file/folder
127 core.get_screen_info()
129 density = <screen density 0.75,1.0,2.0,3.0 ... (dpi)>,
130 display_width = <width of display>,
131 display_height = <height of display>,
132 window_width = <current window width>,
133 window_height = <current window height>
140 path = <full path to game>,
141 gamemods_path = <path>,
142 name = <name of game>,
143 menuicon_path = <full path to menuicon>,
145 addon_mods_paths = {[1] = <path>,},
147 core.get_games() -> table of all games in upper format (possible in async calls)
148 core.get_mapgen_names() -> table of all map generator algorithms registered in
149 the core (possible in async calls)
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.setting_set(name, value)
180 core.setting_get(name) -> string or nil (possible in async calls)
181 core.setting_setbool(name, value)
182 core.setting_getbool(name) -> bool or nil (possible in async calls)
183 core.setting_save() -> nil, save all settings to config file
186 core.get_worlds() -> list of worlds (possible in async calls)
189 path = <full path to world>,
190 name = <name of world>,
191 gameid = <gameid of world>,
194 core.create_world(worldname, gameid)
195 core.delete_world(index)
198 core.gettext(string) -> string
199 ^ look up the translation of a string in the gettext message catalog
200 fgettext(string, ...) -> string
201 ^ call core.gettext(string), replace "$1"..."$9" with the given
202 ^ extra arguments, call core.formspec_escape and return the result
203 core.parse_json(string[, nullvalue]) -> something (possible in async calls)
204 ^ see core.parse_json (lua_api.txt)
206 ^ Return object serialized as a string
207 string:split(separator)
208 ^ eg. string:split("a,b", ",") == {"a","b"}
210 ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
211 core.is_yes(arg) (possible in async calls)
212 ^ returns whether arg can be interpreted as yes
215 core.handle_async(async_job,parameters,finished)
216 ^ execute a function asynchronously
217 ^ async_job is a function receiving one parameter and returning one parameter
218 ^ parameters parameter table passed to async_job
219 ^ finished function to be called once async_job has finished
220 ^ the result of async_job is passed to this function
222 Limitations of Async operations
223 -No access to global lua variables, don't even try
224 -Limited set of available functions
225 e.g. No access to functions modifying menu like core.start,core.close,
226 core.file_open_dialog
231 Settings: see lua_api.txt