]> git.lizzy.rs Git - minetest.git/blob - doc/menu_lua_api.txt
Bump version to 0.4.9
[minetest.git] / doc / menu_lua_api.txt
1 Minetest Lua Mainmenu API Reference 0.4.9
2 ========================================
3
4 Introduction
5 -------------
6 The main menu is defined as a formspec by Lua in builtin/mainmenu.lua
7 Description of formspec language to show your menu is in lua_api.txt
8
9 Callbacks
10 ---------
11 engine.buttonhandler(fields): called when a button is pressed.
12 ^ fields = {name1 = value1, name2 = value2, ...}
13 engine.event_handler(event)
14 ^ event: "MenuQuit", "KeyEnter", "ExitButton" or "EditBoxEnter"
15
16 Gamedata
17 --------
18 The "gamedata" table is read when calling engine.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 engine.start()
31 engine.close()
32
33 Filesystem:
34 engine.get_scriptdir()
35 ^ returns directory of script
36 engine.get_modpath() (possible in async calls)
37 ^ returns path to global modpath
38 engine.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 engine.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 engine.get_gamepath() (possible in async calls)
59 ^ returns path to global gamepath
60 engine.get_texturepath() (possible in async calls)
61 ^ returns path to default textures
62 engine.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 engine.create_dir(absolute_path) (possible in async calls)
67 ^ absolute_path to directory to create (needs to be absolute)
68 ^ returns true/false
69 engine.delete_dir(absolute_path) (possible in async calls)
70 ^ absolute_path to directory to delete (needs to be absolute)
71 ^ returns true/false
72 engine.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 engine.extract_zip(zipfile,destination) [unzip within path required]
78 ^ zipfile to extract
79 ^ destination folder to extract to
80 ^ returns true/false
81 engine.download_file(url,target) (possible in async calls)
82 ^ url to download
83 ^ target to store to
84 ^ returns true/false
85 engine.get_version() (possible in async calls)
86 ^ returns current minetest version
87 engine.sound_play(spec, looped) -> handle
88 ^ spec = SimpleSoundSpec (see lua-api.txt)
89 ^ looped = bool
90 engine.sound_stop(handle)
91
92 GUI:
93 engine.update_formspec(formspec)
94 - engine.set_background(type, texturepath)
95 ^ type: "background", "overlay", "header" or "footer"
96 engine.set_clouds(<true/false>)
97 engine.set_topleft_text(text)
98
99 Games:
100 engine.get_game(index)
101 ^ returns {
102         id               = <id>,
103         path             = <full path to game>,
104         gamemods_path    = <path>,
105         name             = <name of game>,
106         menuicon_path    = <full path to menuicon>,
107         DEPRECATED:
108         addon_mods_paths = {[1] = <path>,},
109 }
110 engine.get_games() -> table of all games in upper format (possible in async calls)
111
112 Favorites:
113 engine.get_favorites(location) -> list of favorites (possible in async calls)
114 ^ location: "local" or "online"
115 ^ returns {
116         [1] = {
117         clients       = <number of clients/nil>,
118         clients_max   = <maximum number of clients/nil>,
119         version       = <server version/nil>,
120         password      = <true/nil>,
121         creative      = <true/nil>,
122         damage        = <true/nil>,
123         pvp           = <true/nil>,
124         description   = <server description/nil>,
125         name          = <server name/nil>,
126         address       = <address of server/nil>,
127         port          = <port>
128         },
129 }
130 engine.delete_favorite(id, location) -> success
131
132 Logging:
133 engine.debug(line) (possible in async calls)
134 ^ Always printed to stderr and logfile (print() is redirected here)
135 engine.log(line) (possible in async calls)
136 engine.log(loglevel, line) (possible in async calls)
137 ^ loglevel one of "error", "action", "info", "verbose"
138
139 Settings:
140 engine.setting_set(name, value)
141 engine.setting_get(name) -> string or nil (possible in async calls)
142 engine.setting_setbool(name, value)
143 engine.setting_getbool(name) -> bool or nil (possible in async calls)
144 engine.setting_save() -> nil, save all settings to config file
145
146 Worlds:
147 engine.get_worlds() -> list of worlds (possible in async calls)
148 ^ returns {
149         [1] = {
150         path   = <full path to world>,
151         name   = <name of world>,
152         gameid = <gameid of world>,
153         },
154 }
155 engine.create_world(worldname, gameid)
156 engine.delete_world(index)
157
158
159 UI:
160 engine.get_textlist_index(textlistname) -> index
161 engine.show_keys_menu()
162 engine.file_open_dialog(formname,caption)
163 ^ shows a file open dialog
164 ^ formname is base name of dialog response returned in fields
165 ^     -if dialog was accepted "_accepted" 
166 ^^       will be added to fieldname containing the path
167 ^     -if dialog was canceled "_cancelled" 
168 ^        will be added to fieldname value is set to formname itself
169 ^ returns nil or selected file/folder
170
171 Helpers:
172 engine.formspec_escape(string) -> string
173 ^ escapes characters [ ] \ , ; that can not be used in formspecs
174 engine.gettext(string) -> string
175 ^ look up the translation of a string in the gettext message catalog
176 fgettext(string, ...) -> string
177 ^ call engine.gettext(string), replace "$1"..."$9" with the given
178 ^ extra arguments, call engine.formspec_escape and return the result
179 engine.parse_json(string[, nullvalue]) -> something (possible in async calls)
180 ^ see minetest.parse_json (lua_api.txt)
181 dump(obj, dumped={})
182 ^ Return object serialized as a string
183 string:split(separator)
184 ^ eg. string:split("a,b", ",") == {"a","b"}
185 string:trim()
186 ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
187 minetest.is_yes(arg) (possible in async calls)
188 ^ returns whether arg can be interpreted as yes
189
190 Async:
191 engine.handle_async(async_job,parameters,finished)
192 ^ execute a function asynchronously
193 ^ async_job is a function receiving one parameter and returning one parameter
194 ^ parameters parameter table passed to async_job
195 ^ finished function to be called once async_job has finished 
196 ^    the result of async_job is passed to this function
197
198 Limitations of Async operations
199  -No access to global lua variables, don't even try
200  -Limited set of available functions
201         e.g. No access to functions modifying menu like engine.start,engine.close,
202         engine.file_open_dialog
203                         
204
205 Class reference
206 ----------------
207 Settings: see lua_api.txt