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)
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 e.g. { "OpenGL", "Software" }
96 core.update_formspec(formspec)
97 core.get_table_index(tablename) -> index
98 ^ can also handle textlists
99 core.formspec_escape(string) -> string
100 ^ escapes characters [ ] \ , ; that can not be used in formspecs
101 core.explode_table_event(string) -> table
102 ^ returns e.g. {type="CHG", row=1, column=2}
103 ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
104 core.explode_textlist_event(string) -> table
105 ^ returns e.g. {type="CHG", index=1}
106 ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
109 core.set_background(type, texturepath,[tile],[minsize])
110 ^ type: "background", "overlay", "header" or "footer"
111 ^ tile: tile the image instead of scaling (background only)
112 ^ minsize: minimum tile size, images are scaled to at least this size prior
113 ^ doing tiling (background only)
114 core.set_clouds(<true/false>)
115 core.set_topleft_text(text)
116 core.show_keys_menu()
117 core.file_open_dialog(formname,caption)
118 ^ shows a file open dialog
119 ^ formname is base name of dialog response returned in fields
120 ^ -if dialog was accepted "_accepted"
121 ^^ will be added to fieldname containing the path
122 ^ -if dialog was canceled "_cancelled"
123 ^ will be added to fieldname value is set to formname itself
124 ^ returns nil or selected file/folder
125 core.get_screen_info()
127 density = <screen density 0.75,1.0,2.0,3.0 ... (dpi)>,
128 display_width = <width of display>,
129 display_height = <height of display>,
130 window_width = <current window width>,
131 window_height = <current window height>
138 path = <full path to game>,
139 gamemods_path = <path>,
140 name = <name of game>,
141 menuicon_path = <full path to menuicon>,
143 addon_mods_paths = {[1] = <path>,},
145 core.get_games() -> table of all games in upper format (possible in async calls)
148 core.get_favorites(location) -> list of favorites (possible in async calls)
149 ^ location: "local" or "online"
152 clients = <number of clients/nil>,
153 clients_max = <maximum number of clients/nil>,
154 version = <server version/nil>,
155 password = <true/nil>,
156 creative = <true/nil>,
159 description = <server description/nil>,
160 name = <server name/nil>,
161 address = <address of server/nil>,
165 core.delete_favorite(id, location) -> success
168 core.debug(line) (possible in async calls)
169 ^ Always printed to stderr and logfile (print() is redirected here)
170 core.log(line) (possible in async calls)
171 core.log(loglevel, line) (possible in async calls)
172 ^ loglevel one of "error", "action", "info", "verbose"
175 core.setting_set(name, value)
176 core.setting_get(name) -> string or nil (possible in async calls)
177 core.setting_setbool(name, value)
178 core.setting_getbool(name) -> bool or nil (possible in async calls)
179 core.setting_save() -> nil, save all settings to config file
182 core.get_worlds() -> list of worlds (possible in async calls)
185 path = <full path to world>,
186 name = <name of world>,
187 gameid = <gameid of world>,
190 core.create_world(worldname, gameid)
191 core.delete_world(index)
194 core.gettext(string) -> string
195 ^ look up the translation of a string in the gettext message catalog
196 fgettext(string, ...) -> string
197 ^ call core.gettext(string), replace "$1"..."$9" with the given
198 ^ extra arguments, call core.formspec_escape and return the result
199 core.parse_json(string[, nullvalue]) -> something (possible in async calls)
200 ^ see core.parse_json (lua_api.txt)
202 ^ Return object serialized as a string
203 string:split(separator)
204 ^ eg. string:split("a,b", ",") == {"a","b"}
206 ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
207 core.is_yes(arg) (possible in async calls)
208 ^ returns whether arg can be interpreted as yes
211 core.handle_async(async_job,parameters,finished)
212 ^ execute a function asynchronously
213 ^ async_job is a function receiving one parameter and returning one parameter
214 ^ parameters parameter table passed to async_job
215 ^ finished function to be called once async_job has finished
216 ^ the result of async_job is passed to this function
218 Limitations of Async operations
219 -No access to global lua variables, don't even try
220 -Limited set of available functions
221 e.g. No access to functions modifying menu like core.start,core.close,
222 core.file_open_dialog
227 Settings: see lua_api.txt