Replace C++ mainmenu by formspec powered one
[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
86 GUI:
87 engine.update_formspec(formspec)
88 - engine.set_background(type, texturepath)
89 ^ type: "background", "overlay", "header" or "footer"
90 engine.set_clouds(<true/false>)
91 engine.set_topleft_text(text)
92
93 Games:
94 engine.get_game(index)
95 ^ returns {
96         id               = <id>,
97         path             = <full path to game>,
98         gamemods_path    = <path>,
99         name             = <name of game>,
100         menuicon_path    = <full path to menuicon>,
101         DEPRECATED:
102         addon_mods_paths = {[1] = <path>,},
103 }
104 engine.get_games() -> table of all games in upper format
105
106 Favorites:
107 engine.get_favorites(location) -> list of favorites
108 ^ location: "local" or "online"
109 ^ returns {
110         [1] = {
111         clients       = <number of clients/nil>,
112         clients_max   = <maximum number of clients/nil>,
113         version       = <server version/nil>,
114         password      = <true/nil>,
115         creative      = <true/nil>,
116         damage        = <true/nil>,
117         pvp           = <true/nil>,
118         description   = <server description/nil>,
119         name          = <server name/nil>,
120         address       = <address of server/nil>,
121         port          = <port>
122         },
123 }
124 engine.delete_favorite(id, location) -> success
125
126 Settings:
127 engine.setting_set(name, value)
128 engine.setting_get(name) -> string or nil
129 engine.setting_setbool(name, value)
130 engine.setting_getbool(name) -> bool or nil
131
132 Worlds:
133 engine.get_worlds() -> list of worlds
134 ^ returns {
135         [1] = {
136         path   = <full path to world>,
137         name   = <name of world>,
138         gameid = <gameid of world>,
139         },
140 }
141 engine.create_world(worldname, gameid)
142 engine.delete_world(index)
143
144
145 UI:
146 engine.get_textlist_index(textlistname) -> index
147 engine.show_keys_menu()
148 engine.file_open_dialog(formname,caption)
149 ^ shows a file open dialog
150 ^ formname is base name of dialog response returned in fields
151 ^     -if dialog was accepted "_accepted" 
152 ^^       will be added to fieldname containing the path
153 ^     -if dialog was canceled "_cancelled" 
154 ^        will be added to fieldname value is set to formname itself
155 ^ returns nil or selected file/folder
156
157 Helpers:
158 dump(obj, dumped={})
159 ^ Return object serialized as a string
160 string:split(separator)
161 ^ eg. string:split("a,b", ",") == {"a","b"}
162 string:trim()
163 ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"