3 Copyright (C) 2013 sapier
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.
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.
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.
23 /******************************************************************************/
25 /******************************************************************************/
26 #include "serverlist.h"
28 /******************************************************************************/
29 /* Typedefs and macros */
30 /******************************************************************************/
31 typedef int (*lua_CFunction) (lua_State *L);
33 /******************************************************************************/
34 /* forward declarations */
35 /******************************************************************************/
39 /******************************************************************************/
41 /******************************************************************************/
43 /** Implementation of lua api support for mainmenu */
48 * initialize given Lua stack
49 * @param L lua stack to initialize
50 * @param engine pointer to GUIEngine element to use as reference
52 static void initialize(lua_State* L,GUIEngine* engine);
54 /** default destructor */
55 virtual ~guiLuaApi() {}
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
64 static std::string getTextData(lua_State *L, std::string name);
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
72 static int getIntegerData(lua_State *L, std::string name,bool& valid);
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
80 static int getBoolData(lua_State *L, std::string name,bool& valid);
83 * get the corresponding engine pointer from a lua stack
84 * @param L stack to read pointer from
85 * @return pointer to GUIEngine
87 static GUIEngine* get_engine(lua_State *L);
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
97 static bool registerFunction( lua_State* L,
104 * check if a path is within some of minetests folders
105 * @param path path to check
108 static bool isMinetestPath(std::string path);
112 static int l_start(lua_State *L);
114 static int l_close(lua_State *L);
116 static int l_create_world(lua_State *L);
118 static int l_delete_world(lua_State *L);
120 static int l_get_worlds(lua_State *L);
122 static int l_get_games(lua_State *L);
124 static int l_get_favorites(lua_State *L);
126 static int l_delete_favorite(lua_State *L);
128 static int l_get_version(lua_State *L);
130 static int l_sound_play(lua_State *L);
132 static int l_sound_stop(lua_State *L);
136 static int l_show_keys_menu(lua_State *L);
138 static int l_show_file_open_dialog(lua_State *L);
140 static int l_set_topleft_text(lua_State *L);
142 static int l_set_clouds(lua_State *L);
144 static int l_get_textlist_index(lua_State *L);
146 static int l_set_background(lua_State *L);
148 static int l_update_formspec(lua_State *L);
152 static int l_setting_set(lua_State *L);
154 static int l_setting_get(lua_State *L);
156 static int l_setting_getbool(lua_State *L);
158 static int l_setting_setbool(lua_State *L);
162 static int l_get_scriptdir(lua_State *L);
164 static int l_get_modpath(lua_State *L);
166 static int l_get_gamepath(lua_State *L);
168 static int l_get_texturepath(lua_State *L);
170 static int l_get_dirlist(lua_State *L);
172 static int l_create_dir(lua_State *L);
174 static int l_delete_dir(lua_State *L);
176 static int l_copy_dir(lua_State *L);
178 static int l_extract_zip(lua_State *L);
180 static int l_get_modstore_details(lua_State *L);
182 static int l_get_modstore_list(lua_State *L);
184 static int l_download_file(lua_State *L);