Add Settings interface for Lua
[oweals/minetest.git] / doc / menu_lua_api.txt
1 Minetest Lua Mainmenu API Reference 0.4.6
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()
37 ^ returns path to global modpath
38 engine.get_modstore_details(modid)
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()
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()
59 ^ returns path to global gamepath
60 engine.get_dirlist(path,onlydirs)
61 ^ path to get subdirs from
62 ^ onlydirs should result contain only dirs?
63 ^ returns list of folders within path
64 engine.create_dir(absolute_path)
65 ^ absolute_path to directory to create (needs to be absolute)
66 ^ returns true/false
67 engine.delete_dir(absolute_path)
68 ^ absolute_path to directory to delete (needs to be absolute)
69 ^ returns true/false
70 engine.copy_dir(source,destination,keep_soure)
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 engine.extract_zip(zipfile,destination) [unzip within path required]
76 ^ zipfile to extract
77 ^ destination folder to extract to
78 ^ returns true/false
79 engine.download_file(url,target)
80 ^ url to download
81 ^ target to store to
82 ^ returns true/false
83 engine.get_version()
84 ^ returns current minetest version
85 engine.sound_play(spec, looped) -> handle
86 ^ spec = SimpleSoundSpec (see lua-api.txt)
87 ^ looped = bool
88 engine.sound_stop(handle)
89
90 GUI:
91 engine.update_formspec(formspec)
92 - engine.set_background(type, texturepath)
93 ^ type: "background", "overlay", "header" or "footer"
94 engine.set_clouds(<true/false>)
95 engine.set_topleft_text(text)
96
97 Games:
98 engine.get_game(index)
99 ^ returns {
100         id               = <id>,
101         path             = <full path to game>,
102         gamemods_path    = <path>,
103         name             = <name of game>,
104         menuicon_path    = <full path to menuicon>,
105         DEPRECATED:
106         addon_mods_paths = {[1] = <path>,},
107 }
108 engine.get_games() -> table of all games in upper format
109
110 Favorites:
111 engine.get_favorites(location) -> list of favorites
112 ^ location: "local" or "online"
113 ^ returns {
114         [1] = {
115         clients       = <number of clients/nil>,
116         clients_max   = <maximum number of clients/nil>,
117         version       = <server version/nil>,
118         password      = <true/nil>,
119         creative      = <true/nil>,
120         damage        = <true/nil>,
121         pvp           = <true/nil>,
122         description   = <server description/nil>,
123         name          = <server name/nil>,
124         address       = <address of server/nil>,
125         port          = <port>
126         },
127 }
128 engine.delete_favorite(id, location) -> success
129
130 Logging:
131 engine.debug(line)
132 ^ Always printed to stderr and logfile (print() is redirected here)
133 engine.log(line)
134 engine.log(loglevel, line)
135 ^ loglevel one of "error", "action", "info", "verbose"
136
137 Settings:
138 engine.setting_set(name, value)
139 engine.setting_get(name) -> string or nil
140 engine.setting_setbool(name, value)
141 engine.setting_getbool(name) -> bool or nil
142 engine.setting_save() -> nil, save all settings to config file
143
144 Worlds:
145 engine.get_worlds() -> list of worlds
146 ^ returns {
147         [1] = {
148         path   = <full path to world>,
149         name   = <name of world>,
150         gameid = <gameid of world>,
151         },
152 }
153 engine.create_world(worldname, gameid)
154 engine.delete_world(index)
155
156
157 UI:
158 engine.get_textlist_index(textlistname) -> index
159 engine.show_keys_menu()
160 engine.file_open_dialog(formname,caption)
161 ^ shows a file open dialog
162 ^ formname is base name of dialog response returned in fields
163 ^     -if dialog was accepted "_accepted" 
164 ^^       will be added to fieldname containing the path
165 ^     -if dialog was canceled "_cancelled" 
166 ^        will be added to fieldname value is set to formname itself
167 ^ returns nil or selected file/folder
168
169 Helpers:
170 engine.formspec_escape(string) -> string
171 ^ escapes characters [ ] \ , ; that can not be used in formspecs
172 engine.gettext(string) -> string
173 ^ look up the translation of a string in the gettext message catalog
174 fgettext(string, ...) -> string
175 ^ call engine.gettext(string), replace "$1"..."$9" with the given
176 ^ extra arguments, call engine.formspec_escape and return the result
177 engine.parse_json(string[, nullvalue]) -> something
178 ^ see minetest.parse_json (lua_api.txt)
179 dump(obj, dumped={})
180 ^ Return object serialized as a string
181 string:split(separator)
182 ^ eg. string:split("a,b", ",") == {"a","b"}
183 string:trim()
184 ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
185 minetest.is_yes(string)
186 ^ returns whether string can be interpreted as yes
187
188 Class reference
189 ----------------
190 Settings: see lua_api.txt