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