]> git.lizzy.rs Git - minetest.git/blob - doc/menu_lua_api.txt
45db89fb0566d870a671aec470db190fbf843bcf
[minetest.git] / doc / menu_lua_api.txt
1 Minetest Lua Mainmenu API Reference 0.4.11
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_scriptdir()
35 ^ returns directory of script
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.get_dirlist(path,onlydirs) (possible in async calls)
63 ^ path to get subdirs from
64 ^ onlydirs should result contain only dirs?
65 ^ returns list of folders within path
66 core.create_dir(absolute_path) (possible in async calls)
67 ^ absolute_path to directory to create (needs to be absolute)
68 ^ returns true/false
69 core.delete_dir(absolute_path) (possible in async calls)
70 ^ absolute_path to directory to delete (needs to be absolute)
71 ^ returns true/false
72 core.copy_dir(source,destination,keep_soure) (possible in async calls)
73 ^ source folder
74 ^ destination folder
75 ^ keep_source DEFAULT true --> if set to false source is deleted after copying
76 ^ returns true/false
77 core.extract_zip(zipfile,destination) [unzip within path required]
78 ^ zipfile to extract
79 ^ destination folder to extract to
80 ^ returns true/false
81 core.download_file(url,target) (possible in async calls)
82 ^ url to download
83 ^ target to store to
84 ^ returns true/false
85 core.get_version() (possible in async calls)
86 ^ returns current core version
87 core.sound_play(spec, looped) -> handle
88 ^ spec = SimpleSoundSpec (see lua-api.txt)
89 ^ looped = bool
90 core.sound_stop(handle)
91 core.get_video_drivers()
92 ^ get list of video drivers supported by engine (not all modes are guaranteed to work)
93 ^ returns list of available video drivers e.g. { "OpenGL", "Software" }
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() -> table of all map generator algorithms registered in
147                            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.gettext(string) -> string
197 ^ look up the translation of a string in the gettext message catalog
198 fgettext(string, ...) -> string
199 ^ call core.gettext(string), replace "$1"..."$9" with the given
200 ^ extra arguments, call core.formspec_escape and return the result
201 core.parse_json(string[, nullvalue]) -> something (possible in async calls)
202 ^ see core.parse_json (lua_api.txt)
203 dump(obj, dumped={})
204 ^ Return object serialized as a string
205 string:split(separator)
206 ^ eg. string:split("a,b", ",") == {"a","b"}
207 string:trim()
208 ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
209 core.is_yes(arg) (possible in async calls)
210 ^ returns whether arg can be interpreted as yes
211
212 Async:
213 core.handle_async(async_job,parameters,finished)
214 ^ execute a function asynchronously
215 ^ async_job is a function receiving one parameter and returning one parameter
216 ^ parameters parameter table passed to async_job
217 ^ finished function to be called once async_job has finished
218 ^    the result of async_job is passed to this function
219
220 Limitations of Async operations
221  -No access to global lua variables, don't even try
222  -Limited set of available functions
223         e.g. No access to functions modifying menu like core.start,core.close,
224         core.file_open_dialog
225                         
226
227 Class reference
228 ----------------
229 Settings: see lua_api.txt