]> git.lizzy.rs Git - dragonfireclient.git/blob - doc/menu_lua_api.txt
Version scheme change: 0.5.0 -> 5.0.0 (#7449)
[dragonfireclient.git] / doc / menu_lua_api.txt
1 Minetest Lua Mainmenu API Reference 5.0.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
69 Formspec:
70 core.update_formspec(formspec)
71 core.get_table_index(tablename) -> index
72 ^ can also handle textlists
73 core.formspec_escape(string) -> string
74 ^ escapes characters [ ] \ , ; that can not be used in formspecs
75 core.explode_table_event(string) -> table
76 ^ returns e.g. {type="CHG", row=1, column=2}
77 ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
78 core.explode_textlist_event(string) -> table
79 ^ returns e.g. {type="CHG", index=1}
80 ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
81
82 GUI:
83 core.set_background(type, texturepath,[tile],[minsize])
84 ^ type: "background", "overlay", "header" or "footer"
85 ^ tile: tile the image instead of scaling (background only)
86 ^ minsize: minimum tile size, images are scaled to at least this size prior
87 ^   doing tiling (background only)
88 core.set_clouds(<true/false>)
89 core.set_topleft_text(text)
90 core.show_keys_menu()
91 core.file_open_dialog(formname,caption)
92 ^ shows a file open dialog
93 ^ formname is base name of dialog response returned in fields
94 ^     -if dialog was accepted "_accepted"
95 ^^       will be added to fieldname containing the path
96 ^     -if dialog was canceled "_cancelled"
97 ^        will be added to fieldname value is set to formname itself
98 ^ returns nil or selected file/folder
99 core.get_screen_info()
100 ^ returns {
101         density         = <screen density 0.75,1.0,2.0,3.0 ... (dpi)>,
102         display_width   = <width of display>,
103         display_height  = <height of display>,
104         window_width    = <current window width>,
105         window_height   = <current window height>
106         }
107
108 ### Content and Packages
109
110 Content - an installed mod, modpack, game, or texture pack (txt)
111 Package - content which is downloadable from the content db, may or may not be installed.
112
113 * core.get_modpath() (possible in async calls)
114         * returns path to global modpath
115 * core.get_clientmodpath() (possible in async calls)
116         * returns path to global client-side modpath
117 * core.get_gamepath() (possible in async calls)
118         * returns path to global gamepath
119 * core.get_texturepath() (possible in async calls)
120         * returns path to default textures
121 * core.get_game(index)
122         * returns:
123
124                 {
125                         id               = <id>,
126                         path             = <full path to game>,
127                         gamemods_path    = <path>,
128                         name             = <name of game>,
129                         menuicon_path    = <full path to menuicon>,
130                         author           = "author",
131                         DEPRECATED:
132                         addon_mods_paths = {[1] = <path>,},
133                 }
134
135 * core.get_games() -> table of all games in upper format (possible in async calls)
136 * core.get_content_info(path)
137         * returns
138
139                 {
140                         name             = "name of content",
141                         type             = "mod" or "modpack" or "game" or "txp",
142                         description      = "description",
143                         author           = "author",
144                         path             = "path/to/content",
145                         depends          = {"mod", "names"}, -- mods only
146                         optional_depends = {"mod", "names"}, -- mods only
147                 }
148
149 * core.get_package_list() -> downloads package list from content db
150         * returns a list of:
151
152                 {
153                         name = "basename",
154                         title = "human readable title",
155                         author = "username",
156                         type = "", -- mod, game, txp
157                         short_description = "description",
158                         url = "",
159                 }
160
161 Favorites:
162 core.get_favorites(location) -> list of favorites (possible in async calls)
163 ^ location: "local" or "online"
164 ^ returns {
165         [1] = {
166         clients       = <number of clients/nil>,
167         clients_max   = <maximum number of clients/nil>,
168         version       = <server version/nil>,
169         password      = <true/nil>,
170         creative      = <true/nil>,
171         damage        = <true/nil>,
172         pvp           = <true/nil>,
173         description   = <server description/nil>,
174         name          = <server name/nil>,
175         address       = <address of server/nil>,
176         port          = <port>
177         },
178 }
179 core.delete_favorite(id, location) -> success
180
181 Logging:
182 core.debug(line) (possible in async calls)
183 ^ Always printed to stderr and logfile (print() is redirected here)
184 core.log(line) (possible in async calls)
185 core.log(loglevel, line) (possible in async calls)
186 ^ loglevel one of "error", "action", "info", "verbose"
187
188 Settings:
189 core.setting_set(name, value)
190 core.setting_get(name) -> string or nil (possible in async calls)
191 core.setting_setbool(name, value)
192 core.setting_getbool(name) -> bool or nil (possible in async calls)
193 core.setting_save() -> nil, save all settings to config file
194
195 Worlds:
196 core.get_worlds() -> list of worlds (possible in async calls)
197 ^ returns {
198         [1] = {
199         path   = <full path to world>,
200         name   = <name of world>,
201         gameid = <gameid of world>,
202         },
203 }
204 core.create_world(worldname, gameid)
205 core.delete_world(index)
206
207 Helpers:
208 core.get_us_time()
209 ^ returns time with microsecond precision
210 core.gettext(string) -> string
211 ^ look up the translation of a string in the gettext message catalog
212 fgettext_ne(string, ...)
213 ^ call core.gettext(string), replace "$1"..."$9" with the given
214 ^ extra arguments and return the result
215 fgettext(string, ...) -> string
216 ^ same as fgettext_ne(), but calls core.formspec_escape before returning result
217 core.parse_json(string[, nullvalue]) -> something (possible in async calls)
218 ^ see core.parse_json (lua_api.txt)
219 dump(obj, dumped={})
220 ^ Return object serialized as a string
221 string:split(separator)
222 ^ eg. string:split("a,b", ",") == {"a","b"}
223 string:trim()
224 ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
225 core.is_yes(arg) (possible in async calls)
226 ^ returns whether arg can be interpreted as yes
227 minetest.encode_base64(string) (possible in async calls)
228 ^ Encodes a string in base64.
229 minetest.decode_base64(string) (possible in async calls)
230 ^ Decodes a string encoded in base64.
231
232 Version compat:
233 core.get_min_supp_proto()
234 ^ returns the minimum supported network protocol version
235 core.get_max_supp_proto()
236 ^ returns the maximum supported network protocol version
237
238 Async:
239 core.handle_async(async_job,parameters,finished)
240 ^ execute a function asynchronously
241 ^ async_job is a function receiving one parameter and returning one parameter
242 ^ parameters parameter table passed to async_job
243 ^ finished function to be called once async_job has finished
244 ^    the result of async_job is passed to this function
245
246 Limitations of Async operations
247  -No access to global lua variables, don't even try
248  -Limited set of available functions
249         e.g. No access to functions modifying menu like core.start,core.close,
250         core.file_open_dialog
251
252
253 Class reference
254 ----------------
255 Settings: see lua_api.txt