Fix my name.
[oweals/minetest.git] / src / guiLuaApi.h
1 /*
2 Minetest
3 Copyright (C) 2013 sapier
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef GUILUAAPI_H_
21 #define GUILUAAPI_H_
22
23 /******************************************************************************/
24 /* Includes                                                                   */
25 /******************************************************************************/
26 #include "serverlist.h"
27
28 /******************************************************************************/
29 /* Typedefs and macros                                                        */
30 /******************************************************************************/
31 typedef int (*lua_CFunction) (lua_State *L);
32
33 /******************************************************************************/
34 /* forward declarations                                                       */
35 /******************************************************************************/
36 class GUIEngine;
37
38
39 /******************************************************************************/
40 /* declarations                                                               */
41 /******************************************************************************/
42
43 /** Implementation of lua api support for mainmenu */
44 class guiLuaApi {
45
46 public:
47         /**
48          * initialize given Lua stack
49          * @param L lua stack to initialize
50          * @param engine pointer to GUIEngine element to use as reference
51          */
52         static void initialize(lua_State* L,GUIEngine* engine);
53
54         /** default destructor */
55         virtual ~guiLuaApi() {}
56
57 private:
58         /**
59          * read a text variable from gamedata table within lua stack
60          * @param L stack to read variable from
61          * @param name name of variable to read
62          * @return string value of requested variable
63          */
64         static std::string getTextData(lua_State *L, std::string name);
65
66         /**
67          * read a integer variable from gamedata table within lua stack
68          * @param L stack to read variable from
69          * @param name name of variable to read
70          * @return integer value of requested variable
71          */
72         static int getIntegerData(lua_State *L, std::string name,bool& valid);
73
74         /**
75          * read a bool variable from gamedata table within lua stack
76          * @param L stack to read variable from
77          * @param name name of variable to read
78          * @return bool value of requested variable
79          */
80         static int getBoolData(lua_State *L, std::string name,bool& valid);
81
82         /**
83          * get the corresponding engine pointer from a lua stack
84          * @param L stack to read pointer from
85          * @return pointer to GUIEngine
86          */
87         static GUIEngine* get_engine(lua_State *L);
88
89
90         /**
91          * register a static member function as lua api call at current position of stack
92          * @param L stack to registe fct to
93          * @param name of function within lua
94          * @param fct C-Function to call on lua call of function
95          * @param top current top of stack
96          */
97         static bool registerFunction(   lua_State* L,
98                                                                         const char* name,
99                                                                         lua_CFunction fct,
100                                                                         int top
101                                                                 );
102
103         /**
104          * check if a path is within some of minetests folders
105          * @param path path to check
106          * @return true/false
107          */
108         static bool isMinetestPath(std::string path);
109
110         //api calls
111
112         static int l_start(lua_State *L);
113
114         static int l_close(lua_State *L);
115
116         static int l_create_world(lua_State *L);
117
118         static int l_delete_world(lua_State *L);
119
120         static int l_get_worlds(lua_State *L);
121
122         static int l_get_games(lua_State *L);
123
124         static int l_get_favorites(lua_State *L);
125
126         static int l_delete_favorite(lua_State *L);
127
128         static int l_get_version(lua_State *L);
129
130         static int l_sound_play(lua_State *L);
131
132         static int l_sound_stop(lua_State *L);
133
134         //gui
135
136         static int l_show_keys_menu(lua_State *L);
137
138         static int l_show_file_open_dialog(lua_State *L);
139
140         static int l_set_topleft_text(lua_State *L);
141
142         static int l_set_clouds(lua_State *L);
143
144         static int l_get_textlist_index(lua_State *L);
145
146         static int l_set_background(lua_State *L);
147
148         static int l_update_formspec(lua_State *L);
149
150         //settings
151
152         static int l_setting_set(lua_State *L);
153
154         static int l_setting_get(lua_State *L);
155
156         static int l_setting_getbool(lua_State *L);
157
158         static int l_setting_setbool(lua_State *L);
159
160         //filesystem
161
162         static int l_get_scriptdir(lua_State *L);
163
164         static int l_get_modpath(lua_State *L);
165
166         static int l_get_gamepath(lua_State *L);
167         
168         static int l_get_texturepath(lua_State *L);
169
170         static int l_get_dirlist(lua_State *L);
171
172         static int l_create_dir(lua_State *L);
173
174         static int l_delete_dir(lua_State *L);
175
176         static int l_copy_dir(lua_State *L);
177
178         static int l_extract_zip(lua_State *L);
179
180         static int l_get_modstore_details(lua_State *L);
181
182         static int l_get_modstore_list(lua_State *L);
183
184         static int l_download_file(lua_State *L);
185
186
187 };
188
189 #endif