Bump version to 0.4.16
[oweals/minetest.git] / doc / menu_lua_api.txt
1 Minetest Lua Mainmenu API Reference 0.4.16
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.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
40 ^ returns {
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>
49 }
50 core.get_modstore_list() (possible in async calls)
51 ^ returns {
52         [1] = {
53                 id               = <numeric id of mod in modstore>,
54                 title    = <human readable title>,
55                 basename = <basename for mod>
56         }
57 }
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.create_dir(absolute_path) (possible in async calls)
63 ^ absolute_path to directory to create (needs to be absolute)
64 ^ returns true/false
65 core.delete_dir(absolute_path) (possible in async calls)
66 ^ absolute_path to directory to delete (needs to be absolute)
67 ^ returns true/false
68 core.copy_dir(source,destination,keep_soure) (possible in async calls)
69 ^ source folder
70 ^ destination folder
71 ^ keep_source DEFAULT true --> if set to false source is deleted after copying
72 ^ returns true/false
73 core.extract_zip(zipfile,destination) [unzip within path required]
74 ^ zipfile to extract
75 ^ destination folder to extract to
76 ^ returns true/false
77 core.download_file(url,target) (possible in async calls)
78 ^ url to download
79 ^ target to store to
80 ^ returns true/false
81 core.get_version() (possible in async calls)
82 ^ returns current core version
83 core.sound_play(spec, looped) -> handle
84 ^ spec = SimpleSoundSpec (see lua-api.txt)
85 ^ looped = bool
86 core.sound_stop(handle)
87 core.get_video_drivers()
88 ^ get list of video drivers supported by engine (not all modes are guaranteed to work)
89 ^ returns list of available video drivers' settings name and 'friendly' display name
90 ^ e.g. { {name="opengl", friendly_name="OpenGL"}, {name="software", friendly_name="Software Renderer"} }
91 ^ first element of returned list is guaranteed to be the NULL driver
92
93 Formspec:
94 core.update_formspec(formspec)
95 core.get_table_index(tablename) -> index
96 ^ can also handle textlists
97 core.formspec_escape(string) -> string
98 ^ escapes characters [ ] \ , ; that can not be used in formspecs
99 core.explode_table_event(string) -> table
100 ^ returns e.g. {type="CHG", row=1, column=2}
101 ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
102 core.explode_textlist_event(string) -> table
103 ^ returns e.g. {type="CHG", index=1}
104 ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
105
106 GUI:
107 core.set_background(type, texturepath,[tile],[minsize])
108 ^ type: "background", "overlay", "header" or "footer"
109 ^ tile: tile the image instead of scaling (background only)
110 ^ minsize: minimum tile size, images are scaled to at least this size prior
111 ^   doing tiling (background only)
112 core.set_clouds(<true/false>)
113 core.set_topleft_text(text)
114 core.show_keys_menu()
115 core.file_open_dialog(formname,caption)
116 ^ shows a file open dialog
117 ^ formname is base name of dialog response returned in fields
118 ^     -if dialog was accepted "_accepted"
119 ^^       will be added to fieldname containing the path
120 ^     -if dialog was canceled "_cancelled"
121 ^        will be added to fieldname value is set to formname itself
122 ^ returns nil or selected file/folder
123 core.get_screen_info()
124 ^ returns {
125         density         = <screen density 0.75,1.0,2.0,3.0 ... (dpi)>,
126         display_width   = <width of display>,
127         display_height  = <height of display>,
128         window_width    = <current window width>,
129         window_height   = <current window height>
130         }
131
132 Games:
133 core.get_game(index)
134 ^ returns {
135         id               = <id>,
136         path             = <full path to game>,
137         gamemods_path    = <path>,
138         name             = <name of game>,
139         menuicon_path    = <full path to menuicon>,
140         DEPRECATED:
141         addon_mods_paths = {[1] = <path>,},
142 }
143 core.get_games() -> table of all games in upper format (possible in async calls)
144 core.get_mapgen_names([include_hidden=false]) -> table of map generator algorithms
145     registered in the core (possible in async calls)
146
147 Favorites:
148 core.get_favorites(location) -> list of favorites (possible in async calls)
149 ^ location: "local" or "online"
150 ^ returns {
151         [1] = {
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>,
157         damage        = <true/nil>,
158         pvp           = <true/nil>,
159         description   = <server description/nil>,
160         name          = <server name/nil>,
161         address       = <address of server/nil>,
162         port          = <port>
163         },
164 }
165 core.delete_favorite(id, location) -> success
166
167 Logging:
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"
173
174 Settings:
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
180
181 Worlds:
182 core.get_worlds() -> list of worlds (possible in async calls)
183 ^ returns {
184         [1] = {
185         path   = <full path to world>,
186         name   = <name of world>,
187         gameid = <gameid of world>,
188         },
189 }
190 core.create_world(worldname, gameid)
191 core.delete_world(index)
192
193 Helpers:
194 core.get_us_time()
195 ^ returns time with microsecond precision
196 core.gettext(string) -> string
197 ^ look up the translation of a string in the gettext message catalog
198 fgettext_ne(string, ...)
199 ^ call core.gettext(string), replace "$1"..."$9" with the given
200 ^ extra arguments and return the result
201 fgettext(string, ...) -> string
202 ^ same as fgettext_ne(), but calls core.formspec_escape before returning result
203 core.parse_json(string[, nullvalue]) -> something (possible in async calls)
204 ^ see core.parse_json (lua_api.txt)
205 dump(obj, dumped={})
206 ^ Return object serialized as a string
207 string:split(separator)
208 ^ eg. string:split("a,b", ",") == {"a","b"}
209 string:trim()
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
213 minetest.encode_base64(string) (possible in async calls)
214 ^ Encodes a string in base64.
215 minetest.decode_base64(string) (possible in async calls)
216 ^ Decodes a string encoded in base64.
217
218 Version compat:
219 core.get_min_supp_proto()
220 ^ returns the minimum supported network protocol version
221 core.get_max_supp_proto()
222 ^ returns the maximum supported network protocol version
223
224 Async:
225 core.handle_async(async_job,parameters,finished)
226 ^ execute a function asynchronously
227 ^ async_job is a function receiving one parameter and returning one parameter
228 ^ parameters parameter table passed to async_job
229 ^ finished function to be called once async_job has finished
230 ^    the result of async_job is passed to this function
231
232 Limitations of Async operations
233  -No access to global lua variables, don't even try
234  -Limited set of available functions
235         e.g. No access to functions modifying menu like core.start,core.close,
236         core.file_open_dialog
237                         
238
239 Class reference
240 ----------------
241 Settings: see lua_api.txt