1 Minetest Lua Mainmenu API Reference 0.5.0
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>,
34 core.get_builtin_path()
35 ^ returns path to builtin root
36 core.get_modpath() (possible in async calls)
37 ^ returns path to global modpath
38 core.get_clientmodpath() (possible in async calls)
39 ^ returns path to global client-side modpath
40 core.get_gamepath() (possible in async calls)
41 ^ returns path to global gamepath
42 core.get_texturepath() (possible in async calls)
43 ^ returns path to default textures
44 core.create_dir(absolute_path) (possible in async calls)
45 ^ absolute_path to directory to create (needs to be absolute)
47 core.delete_dir(absolute_path) (possible in async calls)
48 ^ absolute_path to directory to delete (needs to be absolute)
50 core.copy_dir(source,destination,keep_soure) (possible in async calls)
53 ^ keep_source DEFAULT true --> if set to false source is deleted after copying
55 core.extract_zip(zipfile,destination) [unzip within path required]
57 ^ destination folder to extract to
59 core.download_file(url,target) (possible in async calls)
63 core.get_version() (possible in async calls)
64 ^ returns current core version
65 core.sound_play(spec, looped) -> handle
66 ^ spec = SimpleSoundSpec (see lua-api.txt)
68 core.sound_stop(handle)
69 core.get_video_drivers()
70 ^ get list of video drivers supported by engine (not all modes are guaranteed to work)
71 ^ returns list of available video drivers' settings name and 'friendly' display name
72 ^ e.g. { {name="opengl", friendly_name="OpenGL"}, {name="software", friendly_name="Software Renderer"} }
73 ^ first element of returned list is guaranteed to be the NULL driver
76 core.update_formspec(formspec)
77 core.get_table_index(tablename) -> index
78 ^ can also handle textlists
79 core.formspec_escape(string) -> string
80 ^ escapes characters [ ] \ , ; that can not be used in formspecs
81 core.explode_table_event(string) -> table
82 ^ returns e.g. {type="CHG", row=1, column=2}
83 ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
84 core.explode_textlist_event(string) -> table
85 ^ returns e.g. {type="CHG", index=1}
86 ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
89 core.set_background(type, texturepath,[tile],[minsize])
90 ^ type: "background", "overlay", "header" or "footer"
91 ^ tile: tile the image instead of scaling (background only)
92 ^ minsize: minimum tile size, images are scaled to at least this size prior
93 ^ doing tiling (background only)
94 core.set_clouds(<true/false>)
95 core.set_topleft_text(text)
97 core.file_open_dialog(formname,caption)
98 ^ shows a file open dialog
99 ^ formname is base name of dialog response returned in fields
100 ^ -if dialog was accepted "_accepted"
101 ^^ will be added to fieldname containing the path
102 ^ -if dialog was canceled "_cancelled"
103 ^ will be added to fieldname value is set to formname itself
104 ^ returns nil or selected file/folder
105 core.get_screen_info()
107 density = <screen density 0.75,1.0,2.0,3.0 ... (dpi)>,
108 display_width = <width of display>,
109 display_height = <height of display>,
110 window_width = <current window width>,
111 window_height = <current window height>
118 path = <full path to game>,
119 gamemods_path = <path>,
120 name = <name of game>,
121 menuicon_path = <full path to menuicon>,
123 addon_mods_paths = {[1] = <path>,},
125 core.get_games() -> table of all games in upper format (possible in async calls)
126 core.get_mapgen_names([include_hidden=false]) -> table of map generator algorithms
127 registered in the core (possible in async calls)
130 core.get_favorites(location) -> list of favorites (possible in async calls)
131 ^ location: "local" or "online"
134 clients = <number of clients/nil>,
135 clients_max = <maximum number of clients/nil>,
136 version = <server version/nil>,
137 password = <true/nil>,
138 creative = <true/nil>,
141 description = <server description/nil>,
142 name = <server name/nil>,
143 address = <address of server/nil>,
147 core.delete_favorite(id, location) -> success
150 core.debug(line) (possible in async calls)
151 ^ Always printed to stderr and logfile (print() is redirected here)
152 core.log(line) (possible in async calls)
153 core.log(loglevel, line) (possible in async calls)
154 ^ loglevel one of "error", "action", "info", "verbose"
157 core.setting_set(name, value)
158 core.setting_get(name) -> string or nil (possible in async calls)
159 core.setting_setbool(name, value)
160 core.setting_getbool(name) -> bool or nil (possible in async calls)
161 core.setting_save() -> nil, save all settings to config file
164 core.get_worlds() -> list of worlds (possible in async calls)
167 path = <full path to world>,
168 name = <name of world>,
169 gameid = <gameid of world>,
172 core.create_world(worldname, gameid)
173 core.delete_world(index)
177 ^ returns time with microsecond precision
178 core.gettext(string) -> string
179 ^ look up the translation of a string in the gettext message catalog
180 fgettext_ne(string, ...)
181 ^ call core.gettext(string), replace "$1"..."$9" with the given
182 ^ extra arguments and return the result
183 fgettext(string, ...) -> string
184 ^ same as fgettext_ne(), but calls core.formspec_escape before returning result
185 core.parse_json(string[, nullvalue]) -> something (possible in async calls)
186 ^ see core.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 core.is_yes(arg) (possible in async calls)
194 ^ returns whether arg can be interpreted as yes
195 minetest.encode_base64(string) (possible in async calls)
196 ^ Encodes a string in base64.
197 minetest.decode_base64(string) (possible in async calls)
198 ^ Decodes a string encoded in base64.
201 core.get_min_supp_proto()
202 ^ returns the minimum supported network protocol version
203 core.get_max_supp_proto()
204 ^ returns the maximum supported network protocol version
207 core.handle_async(async_job,parameters,finished)
208 ^ execute a function asynchronously
209 ^ async_job is a function receiving one parameter and returning one parameter
210 ^ parameters parameter table passed to async_job
211 ^ finished function to be called once async_job has finished
212 ^ the result of async_job is passed to this function
214 Limitations of Async operations
215 -No access to global lua variables, don't even try
216 -Limited set of available functions
217 e.g. No access to functions modifying menu like core.start,core.close,
218 core.file_open_dialog
223 Settings: see lua_api.txt