]> git.lizzy.rs Git - minetest.git/blob - doc/menu_lua_api.txt
Remove modstore leftovers. Fix core.show_path_select_dialog documentation (#8572)
[minetest.git] / doc / menu_lua_api.txt
1 Minetest Lua Mainmenu API Reference 5.1.0
2 =========================================
3
4 Introduction
5 -------------
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
8
9 Callbacks
10 ---------
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"
15
16 Gamedata
17 --------
18 The "gamedata" table is read when calling core.start(). It should contain:
19 {
20         playername     = <name>,
21         password       = <password>,
22         address        = <IP/adress>,
23         port           = <port>,
24         selected_world = <index>, -- 0 for client mode
25         singleplayer   = <true/false>,
26 }
27
28 Functions
29 ---------
30 core.start()
31 core.close()
32
33 Filesystem:
34 core.get_builtin_path()
35 ^ returns path to builtin root
36 core.create_dir(absolute_path) (possible in async calls)
37 ^ absolute_path to directory to create (needs to be absolute)
38 ^ returns true/false
39 core.delete_dir(absolute_path) (possible in async calls)
40 ^ absolute_path to directory to delete (needs to be absolute)
41 ^ returns true/false
42 core.copy_dir(source,destination,keep_soure) (possible in async calls)
43 ^ source folder
44 ^ destination folder
45 ^ keep_source DEFAULT true --> if set to false source is deleted after copying
46 ^ returns true/false
47 core.extract_zip(zipfile,destination) [unzip within path required]
48 ^ zipfile to extract
49 ^ destination folder to extract to
50 ^ returns true/false
51 core.download_file(url,target) (possible in async calls)
52 ^ url to download
53 ^ target to store to
54 ^ returns true/false
55 core.get_version() (possible in async calls)
56 ^ returns current core version
57 core.sound_play(spec, looped) -> handle
58 ^ spec = SimpleSoundSpec (see lua-api.txt)
59 ^ looped = bool
60 core.sound_stop(handle)
61 core.get_video_drivers()
62 ^ get list of video drivers supported by engine (not all modes are guaranteed to work)
63 ^ returns list of available video drivers' settings name and 'friendly' display name
64 ^ e.g. { {name="opengl", friendly_name="OpenGL"}, {name="software", friendly_name="Software Renderer"} }
65 ^ first element of returned list is guaranteed to be the NULL driver
66 core.get_mapgen_names([include_hidden=false]) -> table of map generator algorithms
67     registered in the core (possible in async calls)
68 core.get_cache_path() -> path of cache
69
70 Formspec:
71 core.update_formspec(formspec)
72 core.get_table_index(tablename) -> index
73 ^ can also handle textlists
74 core.formspec_escape(string) -> string
75 ^ escapes characters [ ] \ , ; that can not be used in formspecs
76 core.explode_table_event(string) -> table
77 ^ returns e.g. {type="CHG", row=1, column=2}
78 ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
79 core.explode_textlist_event(string) -> table
80 ^ returns e.g. {type="CHG", index=1}
81 ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
82
83 GUI:
84 core.set_background(type, texturepath,[tile],[minsize])
85 ^ type: "background", "overlay", "header" or "footer"
86 ^ tile: tile the image instead of scaling (background only)
87 ^ minsize: minimum tile size, images are scaled to at least this size prior
88 ^   doing tiling (background only)
89 core.set_clouds(<true/false>)
90 core.set_topleft_text(text)
91 core.show_keys_menu()
92 core.show_path_select_dialog(formname, caption, is_file_select)
93 ^ shows a path select dialog
94 ^ formname is base name of dialog response returned in fields
95 ^     -if dialog was accepted "_accepted"
96 ^        will be added to fieldname containing the path
97 ^     -if dialog was canceled "_cancelled"
98 ^        will be added to fieldname value is set to formname itself
99 ^ if `is_file_select` is `true`, a file and not a folder will be selected
100 ^ returns nil or selected file/folder
101 core.get_screen_info()
102 ^ returns {
103         density         = <screen density 0.75,1.0,2.0,3.0 ... (dpi)>,
104         display_width   = <width of display>,
105         display_height  = <height of display>,
106         window_width    = <current window width>,
107         window_height   = <current window height>
108         }
109
110 ### Content and Packages
111
112 Content - an installed mod, modpack, game, or texture pack (txt)
113 Package - content which is downloadable from the content db, may or may not be installed.
114
115 * core.get_modpath() (possible in async calls)
116         * returns path to global modpath
117 * core.get_clientmodpath() (possible in async calls)
118         * returns path to global client-side modpath
119 * core.get_gamepath() (possible in async calls)
120         * returns path to global gamepath
121 * core.get_texturepath() (possible in async calls)
122         * returns path to default textures
123 * core.get_game(index)
124         * returns:
125
126                 {
127                         id               = <id>,
128                         path             = <full path to game>,
129                         gamemods_path    = <path>,
130                         name             = <name of game>,
131                         menuicon_path    = <full path to menuicon>,
132                         author           = "author",
133                         DEPRECATED:
134                         addon_mods_paths = {[1] = <path>,},
135                 }
136
137 * core.get_games() -> table of all games in upper format (possible in async calls)
138 * core.get_content_info(path)
139         * returns
140
141                 {
142                         name             = "name of content",
143                         type             = "mod" or "modpack" or "game" or "txp",
144                         description      = "description",
145                         author           = "author",
146                         path             = "path/to/content",
147                         depends          = {"mod", "names"}, -- mods only
148                         optional_depends = {"mod", "names"}, -- mods only
149                 }
150
151
152 Favorites:
153 core.get_favorites(location) -> list of favorites (possible in async calls)
154 ^ location: "local" or "online"
155 ^ returns {
156         [1] = {
157         clients       = <number of clients/nil>,
158         clients_max   = <maximum number of clients/nil>,
159         version       = <server version/nil>,
160         password      = <true/nil>,
161         creative      = <true/nil>,
162         damage        = <true/nil>,
163         pvp           = <true/nil>,
164         description   = <server description/nil>,
165         name          = <server name/nil>,
166         address       = <address of server/nil>,
167         port          = <port>
168         },
169 }
170 core.delete_favorite(id, location) -> success
171
172 Logging:
173 core.debug(line) (possible in async calls)
174 ^ Always printed to stderr and logfile (print() is redirected here)
175 core.log(line) (possible in async calls)
176 core.log(loglevel, line) (possible in async calls)
177 ^ loglevel one of "error", "action", "info", "verbose"
178
179 Settings:
180 core.settings:set(name, value)
181 core.settings:get(name) -> string or nil (possible in async calls)
182 core.settings:set_bool(name, value)
183 core.settings:get_bool(name) -> bool or nil (possible in async calls)
184 core.settings:save() -> nil, save all settings to config file
185
186 For a complete list of methods of the Settings object see
187 [lua_api.txt](https://github.com/minetest/minetest/blob/master/doc/lua_api.txt)
188
189 Worlds:
190 core.get_worlds() -> list of worlds (possible in async calls)
191 ^ returns {
192         [1] = {
193         path   = <full path to world>,
194         name   = <name of world>,
195         gameid = <gameid of world>,
196         },
197 }
198 core.create_world(worldname, gameid)
199 core.delete_world(index)
200
201 Helpers:
202 core.get_us_time()
203 ^ returns time with microsecond precision
204 core.gettext(string) -> string
205 ^ look up the translation of a string in the gettext message catalog
206 fgettext_ne(string, ...)
207 ^ call core.gettext(string), replace "$1"..."$9" with the given
208 ^ extra arguments and return the result
209 fgettext(string, ...) -> string
210 ^ same as fgettext_ne(), but calls core.formspec_escape before returning result
211 core.parse_json(string[, nullvalue]) -> something (possible in async calls)
212 ^ see core.parse_json (lua_api.txt)
213 dump(obj, dumped={})
214 ^ Return object serialized as a string
215 string:split(separator)
216 ^ eg. string:split("a,b", ",") == {"a","b"}
217 string:trim()
218 ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
219 core.is_yes(arg) (possible in async calls)
220 ^ returns whether arg can be interpreted as yes
221 minetest.encode_base64(string) (possible in async calls)
222 ^ Encodes a string in base64.
223 minetest.decode_base64(string) (possible in async calls)
224 ^ Decodes a string encoded in base64.
225
226 Version compat:
227 core.get_min_supp_proto()
228 ^ returns the minimum supported network protocol version
229 core.get_max_supp_proto()
230 ^ returns the maximum supported network protocol version
231
232 Async:
233 core.handle_async(async_job,parameters,finished)
234 ^ execute a function asynchronously
235 ^ async_job is a function receiving one parameter and returning one parameter
236 ^ parameters parameter table passed to async_job
237 ^ finished function to be called once async_job has finished
238 ^    the result of async_job is passed to this function
239
240 Limitations of Async operations
241  -No access to global lua variables, don't even try
242  -Limited set of available functions
243         e.g. No access to functions modifying menu like core.start,core.close,
244         core.show_path_select_dialog