Main Menu: Add get_clientmodpath API (#5912)
[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_clientmodpath() (possible in async calls)
39 ^ returns path to global client-side modpath
40 core.get_modstore_details(modid) (possible in async calls)
41 ^ modid numeric id of mod in modstore
42 ^ returns {
43         id                      = <numeric id of mod in modstore>,
44         title           = <human readable title>,
45         basename        = <basename for mod>,
46         description = <description of mod>,
47         author          = <author of mod>,
48         download_url= <best match download url>,
49         license         = <short description of license>,
50         rating          = <float value of current rating>
51 }
52 core.get_modstore_list() (possible in async calls)
53 ^ returns {
54         [1] = {
55                 id               = <numeric id of mod in modstore>,
56                 title    = <human readable title>,
57                 basename = <basename for mod>
58         }
59 }
60 core.get_gamepath() (possible in async calls)
61 ^ returns path to global gamepath
62 core.get_texturepath() (possible in async calls)
63 ^ returns path to default textures
64 core.create_dir(absolute_path) (possible in async calls)
65 ^ absolute_path to directory to create (needs to be absolute)
66 ^ returns true/false
67 core.delete_dir(absolute_path) (possible in async calls)
68 ^ absolute_path to directory to delete (needs to be absolute)
69 ^ returns true/false
70 core.copy_dir(source,destination,keep_soure) (possible in async calls)
71 ^ source folder
72 ^ destination folder
73 ^ keep_source DEFAULT true --> if set to false source is deleted after copying
74 ^ returns true/false
75 core.extract_zip(zipfile,destination) [unzip within path required]
76 ^ zipfile to extract
77 ^ destination folder to extract to
78 ^ returns true/false
79 core.download_file(url,target) (possible in async calls)
80 ^ url to download
81 ^ target to store to
82 ^ returns true/false
83 core.get_version() (possible in async calls)
84 ^ returns current core version
85 core.sound_play(spec, looped) -> handle
86 ^ spec = SimpleSoundSpec (see lua-api.txt)
87 ^ looped = bool
88 core.sound_stop(handle)
89 core.get_video_drivers()
90 ^ get list of video drivers supported by engine (not all modes are guaranteed to work)
91 ^ returns list of available video drivers' settings name and 'friendly' display name
92 ^ e.g. { {name="opengl", friendly_name="OpenGL"}, {name="software", friendly_name="Software Renderer"} }
93 ^ first element of returned list is guaranteed to be the NULL driver
94
95 Formspec:
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)
107
108 GUI:
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()
126 ^ returns {
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>
132         }
133
134 Games:
135 core.get_game(index)
136 ^ returns {
137         id               = <id>,
138         path             = <full path to game>,
139         gamemods_path    = <path>,
140         name             = <name of game>,
141         menuicon_path    = <full path to menuicon>,
142         DEPRECATED:
143         addon_mods_paths = {[1] = <path>,},
144 }
145 core.get_games() -> table of all games in upper format (possible in async calls)
146 core.get_mapgen_names([include_hidden=false]) -> table of map generator algorithms
147     registered in the core (possible in async calls)
148
149 Favorites:
150 core.get_favorites(location) -> list of favorites (possible in async calls)
151 ^ location: "local" or "online"
152 ^ returns {
153         [1] = {
154         clients       = <number of clients/nil>,
155         clients_max   = <maximum number of clients/nil>,
156         version       = <server version/nil>,
157         password      = <true/nil>,
158         creative      = <true/nil>,
159         damage        = <true/nil>,
160         pvp           = <true/nil>,
161         description   = <server description/nil>,
162         name          = <server name/nil>,
163         address       = <address of server/nil>,
164         port          = <port>
165         },
166 }
167 core.delete_favorite(id, location) -> success
168
169 Logging:
170 core.debug(line) (possible in async calls)
171 ^ Always printed to stderr and logfile (print() is redirected here)
172 core.log(line) (possible in async calls)
173 core.log(loglevel, line) (possible in async calls)
174 ^ loglevel one of "error", "action", "info", "verbose"
175
176 Settings:
177 core.setting_set(name, value)
178 core.setting_get(name) -> string or nil (possible in async calls)
179 core.setting_setbool(name, value)
180 core.setting_getbool(name) -> bool or nil (possible in async calls)
181 core.setting_save() -> nil, save all settings to config file
182
183 Worlds:
184 core.get_worlds() -> list of worlds (possible in async calls)
185 ^ returns {
186         [1] = {
187         path   = <full path to world>,
188         name   = <name of world>,
189         gameid = <gameid of world>,
190         },
191 }
192 core.create_world(worldname, gameid)
193 core.delete_world(index)
194
195 Helpers:
196 core.get_us_time()
197 ^ returns time with microsecond precision
198 core.gettext(string) -> string
199 ^ look up the translation of a string in the gettext message catalog
200 fgettext_ne(string, ...)
201 ^ call core.gettext(string), replace "$1"..."$9" with the given
202 ^ extra arguments and return the result
203 fgettext(string, ...) -> string
204 ^ same as fgettext_ne(), but calls core.formspec_escape before returning result
205 core.parse_json(string[, nullvalue]) -> something (possible in async calls)
206 ^ see core.parse_json (lua_api.txt)
207 dump(obj, dumped={})
208 ^ Return object serialized as a string
209 string:split(separator)
210 ^ eg. string:split("a,b", ",") == {"a","b"}
211 string:trim()
212 ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
213 core.is_yes(arg) (possible in async calls)
214 ^ returns whether arg can be interpreted as yes
215 minetest.encode_base64(string) (possible in async calls)
216 ^ Encodes a string in base64.
217 minetest.decode_base64(string) (possible in async calls)
218 ^ Decodes a string encoded in base64.
219
220 Version compat:
221 core.get_min_supp_proto()
222 ^ returns the minimum supported network protocol version
223 core.get_max_supp_proto()
224 ^ returns the maximum supported network protocol version
225
226 Async:
227 core.handle_async(async_job,parameters,finished)
228 ^ execute a function asynchronously
229 ^ async_job is a function receiving one parameter and returning one parameter
230 ^ parameters parameter table passed to async_job
231 ^ finished function to be called once async_job has finished
232 ^    the result of async_job is passed to this function
233
234 Limitations of Async operations
235  -No access to global lua variables, don't even try
236  -Limited set of available functions
237         e.g. No access to functions modifying menu like core.start,core.close,
238         core.file_open_dialog
239
240
241 Class reference
242 ----------------
243 Settings: see lua_api.txt