]> git.lizzy.rs Git - minetest.git/blob - doc/menu_lua_api.txt
Move the old stuff to doc
[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 Formspec:
93 engine.update_formspec(formspec)
94 engine.get_table_index(tablename) -> index
95 ^ can also handle textlists
96 engine.formspec_escape(string) -> string
97 ^ escapes characters [ ] \ , ; that can not be used in formspecs
98 engine.explode_table_event(string) -> table
99 ^ returns e.g. {type="CHG", row=1, column=2}
100 ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
101 engine.explode_textlist_event(string) -> table
102 ^ returns e.g. {type="CHG", index=1}
103 ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
104
105 GUI:
106 engine.set_background(type, texturepath)
107 ^ type: "background", "overlay", "header" or "footer"
108 engine.set_clouds(<true/false>)
109 engine.set_topleft_text(text)
110 engine.show_keys_menu()
111 engine.file_open_dialog(formname,caption)
112 ^ shows a file open dialog
113 ^ formname is base name of dialog response returned in fields
114 ^     -if dialog was accepted "_accepted"
115 ^^       will be added to fieldname containing the path
116 ^     -if dialog was canceled "_cancelled"
117 ^        will be added to fieldname value is set to formname itself
118 ^ returns nil or selected file/folder
119
120 Games:
121 engine.get_game(index)
122 ^ returns {
123         id               = <id>,
124         path             = <full path to game>,
125         gamemods_path    = <path>,
126         name             = <name of game>,
127         menuicon_path    = <full path to menuicon>,
128         DEPRECATED:
129         addon_mods_paths = {[1] = <path>,},
130 }
131 engine.get_games() -> table of all games in upper format (possible in async calls)
132
133 Favorites:
134 engine.get_favorites(location) -> list of favorites (possible in async calls)
135 ^ location: "local" or "online"
136 ^ returns {
137         [1] = {
138         clients       = <number of clients/nil>,
139         clients_max   = <maximum number of clients/nil>,
140         version       = <server version/nil>,
141         password      = <true/nil>,
142         creative      = <true/nil>,
143         damage        = <true/nil>,
144         pvp           = <true/nil>,
145         description   = <server description/nil>,
146         name          = <server name/nil>,
147         address       = <address of server/nil>,
148         port          = <port>
149         },
150 }
151 engine.delete_favorite(id, location) -> success
152
153 Logging:
154 engine.debug(line) (possible in async calls)
155 ^ Always printed to stderr and logfile (print() is redirected here)
156 engine.log(line) (possible in async calls)
157 engine.log(loglevel, line) (possible in async calls)
158 ^ loglevel one of "error", "action", "info", "verbose"
159
160 Settings:
161 engine.setting_set(name, value)
162 engine.setting_get(name) -> string or nil (possible in async calls)
163 engine.setting_setbool(name, value)
164 engine.setting_getbool(name) -> bool or nil (possible in async calls)
165 engine.setting_save() -> nil, save all settings to config file
166
167 Worlds:
168 engine.get_worlds() -> list of worlds (possible in async calls)
169 ^ returns {
170         [1] = {
171         path   = <full path to world>,
172         name   = <name of world>,
173         gameid = <gameid of world>,
174         },
175 }
176 engine.create_world(worldname, gameid)
177 engine.delete_world(index)
178
179 Helpers:
180 engine.gettext(string) -> string
181 ^ look up the translation of a string in the gettext message catalog
182 fgettext(string, ...) -> string
183 ^ call engine.gettext(string), replace "$1"..."$9" with the given
184 ^ extra arguments, call engine.formspec_escape and return the result
185 engine.parse_json(string[, nullvalue]) -> something (possible in async calls)
186 ^ see minetest.parse_json (lua_api.txt)
187 dump(obj, dumped={})
188 ^ Return object serialized as a string
189 string:split(separator)
190 ^ eg. string:split("a,b", ",") == {"a","b"}
191 string:trim()
192 ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
193 minetest.is_yes(arg) (possible in async calls)
194 ^ returns whether arg can be interpreted as yes
195
196 Async:
197 engine.handle_async(async_job,parameters,finished)
198 ^ execute a function asynchronously
199 ^ async_job is a function receiving one parameter and returning one parameter
200 ^ parameters parameter table passed to async_job
201 ^ finished function to be called once async_job has finished 
202 ^    the result of async_job is passed to this function
203
204 Limitations of Async operations
205  -No access to global lua variables, don't even try
206  -Limited set of available functions
207         e.g. No access to functions modifying menu like engine.start,engine.close,
208         engine.file_open_dialog
209                         
210
211 Class reference
212 ----------------
213 Settings: see lua_api.txt