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.
20 #include "lua_api/l_mainmenu.h"
21 #include "lua_api/l_internal.h"
22 #include "common/c_content.h"
23 #include "cpp_api/s_async.h"
24 #include "gui/guiEngine.h"
25 #include "gui/guiMainMenu.h"
26 #include "gui/guiKeyChangeMenu.h"
27 #include "gui/guiPathSelectMenu.h"
32 #include "convert_json.h"
33 #include "serverlist.h"
34 #include "mapgen/mapgen.h"
37 #include <IFileArchive.h>
38 #include <IFileSystem.h>
39 #include "client/renderingengine.h"
42 /******************************************************************************/
43 std::string ModApiMainMenu::getTextData(lua_State *L, std::string name)
45 lua_getglobal(L, "gamedata");
47 lua_getfield(L, -1, name.c_str());
52 return luaL_checkstring(L, -1);
55 /******************************************************************************/
56 int ModApiMainMenu::getIntegerData(lua_State *L, std::string name,bool& valid)
58 lua_getglobal(L, "gamedata");
60 lua_getfield(L, -1, name.c_str());
62 if(lua_isnil(L, -1)) {
68 return luaL_checkinteger(L, -1);
71 /******************************************************************************/
72 int ModApiMainMenu::getBoolData(lua_State *L, std::string name,bool& valid)
74 lua_getglobal(L, "gamedata");
76 lua_getfield(L, -1, name.c_str());
78 if(lua_isnil(L, -1)) {
84 return lua_toboolean(L, -1);
87 /******************************************************************************/
88 int ModApiMainMenu::l_update_formspec(lua_State *L)
90 GUIEngine* engine = getGuiEngine(L);
91 sanity_check(engine != NULL);
93 if (engine->m_startgame)
97 std::string formspec(luaL_checkstring(L, 1));
99 if (engine->m_formspecgui != 0) {
100 engine->m_formspecgui->setForm(formspec);
106 /******************************************************************************/
107 int ModApiMainMenu::l_start(lua_State *L)
109 GUIEngine* engine = getGuiEngine(L);
110 sanity_check(engine != NULL);
112 //update c++ gamedata from lua table
116 MainMenuData *data = engine->m_data;
118 data->selected_world = getIntegerData(L, "selected_world",valid) -1;
119 data->simple_singleplayer_mode = getBoolData(L,"singleplayer",valid);
120 data->do_reconnect = getBoolData(L, "do_reconnect", valid);
121 if (!data->do_reconnect) {
122 data->name = getTextData(L,"playername");
123 data->password = getTextData(L,"password");
124 data->address = getTextData(L,"address");
125 data->port = getTextData(L,"port");
127 data->serverdescription = getTextData(L,"serverdescription");
128 data->servername = getTextData(L,"servername");
130 //close menu next time
131 engine->m_startgame = true;
135 /******************************************************************************/
136 int ModApiMainMenu::l_close(lua_State *L)
138 GUIEngine* engine = getGuiEngine(L);
139 sanity_check(engine != NULL);
141 engine->m_kill = true;
145 /******************************************************************************/
146 int ModApiMainMenu::l_set_background(lua_State *L)
148 GUIEngine* engine = getGuiEngine(L);
149 sanity_check(engine != NULL);
151 std::string backgroundlevel(luaL_checkstring(L, 1));
152 std::string texturename(luaL_checkstring(L, 2));
154 bool tile_image = false;
156 unsigned int minsize = 16;
158 if (!lua_isnone(L, 3)) {
159 tile_image = lua_toboolean(L, 3);
162 if (!lua_isnone(L, 4)) {
163 minsize = lua_tonumber(L, 4);
166 if (backgroundlevel == "background") {
167 retval |= engine->setTexture(TEX_LAYER_BACKGROUND, texturename,
168 tile_image, minsize);
171 if (backgroundlevel == "overlay") {
172 retval |= engine->setTexture(TEX_LAYER_OVERLAY, texturename,
173 tile_image, minsize);
176 if (backgroundlevel == "header") {
177 retval |= engine->setTexture(TEX_LAYER_HEADER, texturename,
178 tile_image, minsize);
181 if (backgroundlevel == "footer") {
182 retval |= engine->setTexture(TEX_LAYER_FOOTER, texturename,
183 tile_image, minsize);
186 lua_pushboolean(L,retval);
190 /******************************************************************************/
191 int ModApiMainMenu::l_set_clouds(lua_State *L)
193 GUIEngine* engine = getGuiEngine(L);
194 sanity_check(engine != NULL);
196 bool value = lua_toboolean(L,1);
198 engine->m_clouds_enabled = value;
203 /******************************************************************************/
204 int ModApiMainMenu::l_get_textlist_index(lua_State *L)
206 // get_table_index accepts both tables and textlists
207 return l_get_table_index(L);
210 /******************************************************************************/
211 int ModApiMainMenu::l_get_table_index(lua_State *L)
213 GUIEngine* engine = getGuiEngine(L);
214 sanity_check(engine != NULL);
216 std::string tablename(luaL_checkstring(L, 1));
217 GUITable *table = engine->m_menu->getTable(tablename);
218 s32 selection = table ? table->getSelected() : 0;
221 lua_pushinteger(L, selection);
227 /******************************************************************************/
228 int ModApiMainMenu::l_get_worlds(lua_State *L)
230 std::vector<WorldSpec> worlds = getAvailableWorlds();
233 int top = lua_gettop(L);
234 unsigned int index = 1;
236 for (const WorldSpec &world : worlds) {
237 lua_pushnumber(L,index);
240 int top_lvl2 = lua_gettop(L);
242 lua_pushstring(L,"path");
243 lua_pushstring(L, world.path.c_str());
244 lua_settable(L, top_lvl2);
246 lua_pushstring(L,"name");
247 lua_pushstring(L, world.name.c_str());
248 lua_settable(L, top_lvl2);
250 lua_pushstring(L,"gameid");
251 lua_pushstring(L, world.gameid.c_str());
252 lua_settable(L, top_lvl2);
254 lua_settable(L, top);
260 /******************************************************************************/
261 int ModApiMainMenu::l_get_games(lua_State *L)
263 std::vector<SubgameSpec> games = getAvailableGames();
266 int top = lua_gettop(L);
267 unsigned int index = 1;
269 for (const SubgameSpec &game : games) {
270 lua_pushnumber(L,index);
272 int top_lvl2 = lua_gettop(L);
274 lua_pushstring(L,"id");
275 lua_pushstring(L, game.id.c_str());
276 lua_settable(L, top_lvl2);
278 lua_pushstring(L,"path");
279 lua_pushstring(L, game.path.c_str());
280 lua_settable(L, top_lvl2);
282 lua_pushstring(L,"gamemods_path");
283 lua_pushstring(L, game.gamemods_path.c_str());
284 lua_settable(L, top_lvl2);
286 lua_pushstring(L,"name");
287 lua_pushstring(L, game.name.c_str());
288 lua_settable(L, top_lvl2);
290 lua_pushstring(L,"menuicon_path");
291 lua_pushstring(L, game.menuicon_path.c_str());
292 lua_settable(L, top_lvl2);
294 lua_pushstring(L,"addon_mods_paths");
296 int table2 = lua_gettop(L);
297 int internal_index=1;
298 for (const std::string &addon_mods_path : game.addon_mods_paths) {
299 lua_pushnumber(L,internal_index);
300 lua_pushstring(L, addon_mods_path.c_str());
301 lua_settable(L, table2);
304 lua_settable(L, top_lvl2);
305 lua_settable(L, top);
310 /******************************************************************************/
311 int ModApiMainMenu::l_get_favorites(lua_State *L)
313 std::string listtype = "local";
315 if (!lua_isnone(L,1)) {
316 listtype = luaL_checkstring(L,1);
319 std::vector<ServerListSpec> servers;
321 if(listtype == "online") {
322 servers = ServerList::getOnline();
324 servers = ServerList::getLocal();
328 int top = lua_gettop(L);
329 unsigned int index = 1;
331 for (const Json::Value &server : servers) {
333 lua_pushnumber(L,index);
336 int top_lvl2 = lua_gettop(L);
338 if (!server["clients"].asString().empty()) {
339 std::string clients_raw = server["clients"].asString();
341 int numbervalue = strtol(clients_raw.c_str(),&endptr,10);
343 if ((!clients_raw.empty()) && (*endptr == 0)) {
344 lua_pushstring(L,"clients");
345 lua_pushnumber(L,numbervalue);
346 lua_settable(L, top_lvl2);
350 if (!server["clients_max"].asString().empty()) {
352 std::string clients_max_raw = server["clients_max"].asString();
354 int numbervalue = strtol(clients_max_raw.c_str(),&endptr,10);
356 if ((!clients_max_raw.empty()) && (*endptr == 0)) {
357 lua_pushstring(L,"clients_max");
358 lua_pushnumber(L,numbervalue);
359 lua_settable(L, top_lvl2);
363 if (!server["version"].asString().empty()) {
364 lua_pushstring(L,"version");
365 std::string topush = server["version"].asString();
366 lua_pushstring(L,topush.c_str());
367 lua_settable(L, top_lvl2);
370 if (!server["proto_min"].asString().empty()) {
371 lua_pushstring(L,"proto_min");
372 lua_pushinteger(L, server["proto_min"].asInt());
373 lua_settable(L, top_lvl2);
376 if (!server["proto_max"].asString().empty()) {
377 lua_pushstring(L,"proto_max");
378 lua_pushinteger(L, server["proto_max"].asInt());
379 lua_settable(L, top_lvl2);
382 if (!server["password"].asString().empty()) {
383 lua_pushstring(L,"password");
384 lua_pushboolean(L, server["password"].asBool());
385 lua_settable(L, top_lvl2);
388 if (!server["creative"].asString().empty()) {
389 lua_pushstring(L,"creative");
390 lua_pushboolean(L, server["creative"].asBool());
391 lua_settable(L, top_lvl2);
394 if (!server["damage"].asString().empty()) {
395 lua_pushstring(L,"damage");
396 lua_pushboolean(L, server["damage"].asBool());
397 lua_settable(L, top_lvl2);
400 if (!server["pvp"].asString().empty()) {
401 lua_pushstring(L,"pvp");
402 lua_pushboolean(L, server["pvp"].asBool());
403 lua_settable(L, top_lvl2);
406 if (!server["description"].asString().empty()) {
407 lua_pushstring(L,"description");
408 std::string topush = server["description"].asString();
409 lua_pushstring(L,topush.c_str());
410 lua_settable(L, top_lvl2);
413 if (!server["name"].asString().empty()) {
414 lua_pushstring(L,"name");
415 std::string topush = server["name"].asString();
416 lua_pushstring(L,topush.c_str());
417 lua_settable(L, top_lvl2);
420 if (!server["address"].asString().empty()) {
421 lua_pushstring(L,"address");
422 std::string topush = server["address"].asString();
423 lua_pushstring(L,topush.c_str());
424 lua_settable(L, top_lvl2);
427 if (!server["port"].asString().empty()) {
428 lua_pushstring(L,"port");
429 std::string topush = server["port"].asString();
430 lua_pushstring(L,topush.c_str());
431 lua_settable(L, top_lvl2);
434 if (server.isMember("ping")) {
435 float ping = server["ping"].asFloat();
436 lua_pushstring(L, "ping");
437 lua_pushnumber(L, ping);
438 lua_settable(L, top_lvl2);
441 lua_settable(L, top);
447 /******************************************************************************/
448 int ModApiMainMenu::l_delete_favorite(lua_State *L)
450 std::vector<ServerListSpec> servers;
452 std::string listtype = "local";
454 if (!lua_isnone(L,2)) {
455 listtype = luaL_checkstring(L,2);
458 if ((listtype != "local") &&
459 (listtype != "online"))
463 if(listtype == "online") {
464 servers = ServerList::getOnline();
466 servers = ServerList::getLocal();
469 int fav_idx = luaL_checkinteger(L,1) -1;
471 if ((fav_idx >= 0) &&
472 (fav_idx < (int) servers.size())) {
474 ServerList::deleteEntry(servers[fav_idx]);
480 /******************************************************************************/
481 int ModApiMainMenu::l_show_keys_menu(lua_State *L)
483 GUIEngine* engine = getGuiEngine(L);
484 sanity_check(engine != NULL);
486 GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(RenderingEngine::get_gui_env(),
489 engine->m_menumanager);
494 /******************************************************************************/
495 int ModApiMainMenu::l_create_world(lua_State *L)
497 const char *name = luaL_checkstring(L, 1);
498 int gameidx = luaL_checkinteger(L,2) -1;
500 std::string path = porting::path_user + DIR_DELIM
504 std::vector<SubgameSpec> games = getAvailableGames();
506 if ((gameidx >= 0) &&
507 (gameidx < (int) games.size())) {
509 // Create world if it doesn't exist
510 if (!loadGameConfAndInitWorld(path, games[gameidx])) {
511 lua_pushstring(L, "Failed to initialize world");
516 lua_pushstring(L, "Invalid game index");
521 /******************************************************************************/
522 int ModApiMainMenu::l_delete_world(lua_State *L)
524 int worldidx = luaL_checkinteger(L,1) -1;
526 std::vector<WorldSpec> worlds = getAvailableWorlds();
528 if ((worldidx >= 0) &&
529 (worldidx < (int) worlds.size())) {
531 WorldSpec spec = worlds[worldidx];
533 std::vector<std::string> paths;
534 paths.push_back(spec.path);
535 fs::GetRecursiveSubPaths(spec.path, paths);
538 if (!fs::DeletePaths(paths)) {
539 lua_pushstring(L, "Failed to delete world");
546 lua_pushstring(L, "Invalid world index");
551 /******************************************************************************/
552 int ModApiMainMenu::l_set_topleft_text(lua_State *L)
554 GUIEngine* engine = getGuiEngine(L);
555 sanity_check(engine != NULL);
559 if (!lua_isnone(L,1) && !lua_isnil(L,1))
560 text = luaL_checkstring(L, 1);
562 engine->setTopleftText(text);
566 /******************************************************************************/
567 int ModApiMainMenu::l_get_mapgen_names(lua_State *L)
569 std::vector<const char *> names;
570 Mapgen::getMapgenNames(&names, lua_toboolean(L, 1));
573 for (size_t i = 0; i != names.size(); i++) {
574 lua_pushstring(L, names[i]);
575 lua_rawseti(L, -2, i + 1);
582 /******************************************************************************/
583 int ModApiMainMenu::l_get_modpath(lua_State *L)
585 std::string modpath = fs::RemoveRelativePathComponents(
586 porting::path_user + DIR_DELIM + "mods" + DIR_DELIM);
587 lua_pushstring(L, modpath.c_str());
591 /******************************************************************************/
592 int ModApiMainMenu::l_get_clientmodpath(lua_State *L)
594 std::string modpath = fs::RemoveRelativePathComponents(
595 porting::path_user + DIR_DELIM + "clientmods" + DIR_DELIM);
596 lua_pushstring(L, modpath.c_str());
600 /******************************************************************************/
601 int ModApiMainMenu::l_get_gamepath(lua_State *L)
603 std::string gamepath = fs::RemoveRelativePathComponents(
604 porting::path_user + DIR_DELIM + "games" + DIR_DELIM);
605 lua_pushstring(L, gamepath.c_str());
609 /******************************************************************************/
610 int ModApiMainMenu::l_get_texturepath(lua_State *L)
612 std::string gamepath = fs::RemoveRelativePathComponents(
613 porting::path_user + DIR_DELIM + "textures");
614 lua_pushstring(L, gamepath.c_str());
618 int ModApiMainMenu::l_get_texturepath_share(lua_State *L)
620 std::string gamepath = fs::RemoveRelativePathComponents(
621 porting::path_share + DIR_DELIM + "textures");
622 lua_pushstring(L, gamepath.c_str());
626 /******************************************************************************/
627 int ModApiMainMenu::l_create_dir(lua_State *L) {
628 const char *path = luaL_checkstring(L, 1);
630 if (ModApiMainMenu::isMinetestPath(path)) {
631 lua_pushboolean(L, fs::CreateAllDirs(path));
635 lua_pushboolean(L, false);
639 /******************************************************************************/
640 int ModApiMainMenu::l_delete_dir(lua_State *L)
642 const char *path = luaL_checkstring(L, 1);
644 std::string absolute_path = fs::RemoveRelativePathComponents(path);
646 if (ModApiMainMenu::isMinetestPath(absolute_path)) {
647 lua_pushboolean(L, fs::RecursiveDelete(absolute_path));
651 lua_pushboolean(L, false);
655 /******************************************************************************/
656 int ModApiMainMenu::l_copy_dir(lua_State *L)
658 const char *source = luaL_checkstring(L, 1);
659 const char *destination = luaL_checkstring(L, 2);
661 bool keep_source = true;
663 if ((!lua_isnone(L,3)) &&
665 keep_source = lua_toboolean(L,3);
668 std::string absolute_destination = fs::RemoveRelativePathComponents(destination);
669 std::string absolute_source = fs::RemoveRelativePathComponents(source);
671 if ((ModApiMainMenu::isMinetestPath(absolute_destination))) {
672 bool retval = fs::CopyDir(absolute_source,absolute_destination);
674 if (retval && (!keep_source)) {
676 retval &= fs::RecursiveDelete(absolute_source);
678 lua_pushboolean(L,retval);
681 lua_pushboolean(L,false);
685 /******************************************************************************/
686 int ModApiMainMenu::l_extract_zip(lua_State *L)
688 const char *zipfile = luaL_checkstring(L, 1);
689 const char *destination = luaL_checkstring(L, 2);
691 std::string absolute_destination = fs::RemoveRelativePathComponents(destination);
693 if (ModApiMainMenu::isMinetestPath(absolute_destination)) {
694 fs::CreateAllDirs(absolute_destination);
696 io::IFileSystem *fs = RenderingEngine::get_filesystem();
698 if (!fs->addFileArchive(zipfile,true,false,io::EFAT_ZIP)) {
699 lua_pushboolean(L,false);
703 sanity_check(fs->getFileArchiveCount() > 0);
705 /**********************************************************************/
706 /* WARNING this is not threadsafe!! */
707 /**********************************************************************/
708 io::IFileArchive* opened_zip =
709 fs->getFileArchive(fs->getFileArchiveCount()-1);
711 const io::IFileList* files_in_zip = opened_zip->getFileList();
713 unsigned int number_of_files = files_in_zip->getFileCount();
715 for (unsigned int i=0; i < number_of_files; i++) {
716 std::string fullpath = destination;
717 fullpath += DIR_DELIM;
718 fullpath += files_in_zip->getFullFileName(i).c_str();
719 std::string fullpath_dir = fs::RemoveLastPathComponent(fullpath);
721 if (!files_in_zip->isDirectory(i)) {
722 if (!fs::PathExists(fullpath_dir) && !fs::CreateAllDirs(fullpath_dir)) {
723 fs->removeFileArchive(fs->getFileArchiveCount()-1);
724 lua_pushboolean(L,false);
728 io::IReadFile* toread = opened_zip->createAndOpenFile(i);
730 FILE *targetfile = fopen(fullpath.c_str(),"wb");
732 if (targetfile == NULL) {
733 fs->removeFileArchive(fs->getFileArchiveCount()-1);
734 lua_pushboolean(L,false);
738 char read_buffer[1024];
741 while (total_read < toread->getSize()) {
743 unsigned int bytes_read =
744 toread->read(read_buffer,sizeof(read_buffer));
745 if ((bytes_read == 0 ) ||
746 (fwrite(read_buffer, 1, bytes_read, targetfile) != bytes_read))
749 fs->removeFileArchive(fs->getFileArchiveCount()-1);
750 lua_pushboolean(L,false);
753 total_read += bytes_read;
761 fs->removeFileArchive(fs->getFileArchiveCount()-1);
762 lua_pushboolean(L,true);
766 lua_pushboolean(L,false);
770 /******************************************************************************/
771 int ModApiMainMenu::l_get_mainmenu_path(lua_State *L)
773 GUIEngine* engine = getGuiEngine(L);
774 sanity_check(engine != NULL);
776 lua_pushstring(L,engine->getScriptDir().c_str());
780 /******************************************************************************/
781 bool ModApiMainMenu::isMinetestPath(std::string path)
783 if (fs::PathStartsWith(path,fs::TempPath()))
787 if (fs::PathStartsWith(path,fs::RemoveRelativePathComponents(porting::path_share + DIR_DELIM + "games")))
791 if (fs::PathStartsWith(path,fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM + "mods")))
795 if (fs::PathStartsWith(path,fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM + "worlds")))
802 /******************************************************************************/
803 int ModApiMainMenu::l_show_path_select_dialog(lua_State *L)
805 GUIEngine* engine = getGuiEngine(L);
806 sanity_check(engine != NULL);
808 const char *formname= luaL_checkstring(L, 1);
809 const char *title = luaL_checkstring(L, 2);
810 bool is_file_select = lua_toboolean(L, 3);
812 GUIFileSelectMenu* fileOpenMenu =
813 new GUIFileSelectMenu(RenderingEngine::get_gui_env(),
816 engine->m_menumanager,
820 fileOpenMenu->setTextDest(engine->m_buttonhandler);
821 fileOpenMenu->drop();
825 /******************************************************************************/
826 int ModApiMainMenu::l_download_file(lua_State *L)
828 const char *url = luaL_checkstring(L, 1);
829 const char *target = luaL_checkstring(L, 2);
832 std::string absolute_destination = fs::RemoveRelativePathComponents(target);
834 if (ModApiMainMenu::isMinetestPath(absolute_destination)) {
835 if (GUIEngine::downloadFile(url,absolute_destination)) {
836 lua_pushboolean(L,true);
840 errorstream << "DOWNLOAD denied: " << absolute_destination
841 << " isn't a allowed path" << std::endl;
843 lua_pushboolean(L,false);
847 /******************************************************************************/
848 int ModApiMainMenu::l_get_video_drivers(lua_State *L)
850 std::vector<irr::video::E_DRIVER_TYPE> drivers = RenderingEngine::getSupportedVideoDrivers();
853 for (u32 i = 0; i != drivers.size(); i++) {
854 const char *name = RenderingEngine::getVideoDriverName(drivers[i]);
855 const char *fname = RenderingEngine::getVideoDriverFriendlyName(drivers[i]);
858 lua_pushstring(L, name);
859 lua_setfield(L, -2, "name");
860 lua_pushstring(L, fname);
861 lua_setfield(L, -2, "friendly_name");
863 lua_rawseti(L, -2, i + 1);
869 /******************************************************************************/
870 int ModApiMainMenu::l_get_video_modes(lua_State *L)
872 std::vector<core::vector3d<u32> > videomodes
873 = RenderingEngine::getSupportedVideoModes();
876 for (u32 i = 0; i != videomodes.size(); i++) {
878 lua_pushnumber(L, videomodes[i].X);
879 lua_setfield(L, -2, "w");
880 lua_pushnumber(L, videomodes[i].Y);
881 lua_setfield(L, -2, "h");
882 lua_pushnumber(L, videomodes[i].Z);
883 lua_setfield(L, -2, "depth");
885 lua_rawseti(L, -2, i + 1);
891 /******************************************************************************/
892 int ModApiMainMenu::l_gettext(lua_State *L)
894 std::string text = strgettext(std::string(luaL_checkstring(L, 1)));
895 lua_pushstring(L, text.c_str());
900 /******************************************************************************/
901 int ModApiMainMenu::l_get_screen_info(lua_State *L)
904 int top = lua_gettop(L);
905 lua_pushstring(L,"density");
906 lua_pushnumber(L,RenderingEngine::getDisplayDensity());
907 lua_settable(L, top);
909 lua_pushstring(L,"display_width");
910 lua_pushnumber(L,RenderingEngine::getDisplaySize().X);
911 lua_settable(L, top);
913 lua_pushstring(L,"display_height");
914 lua_pushnumber(L,RenderingEngine::getDisplaySize().Y);
915 lua_settable(L, top);
917 const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize();
918 lua_pushstring(L,"window_width");
919 lua_pushnumber(L, window_size.X);
920 lua_settable(L, top);
922 lua_pushstring(L,"window_height");
923 lua_pushnumber(L, window_size.Y);
924 lua_settable(L, top);
928 /******************************************************************************/
929 int ModApiMainMenu::l_get_min_supp_proto(lua_State *L)
931 lua_pushinteger(L, CLIENT_PROTOCOL_VERSION_MIN);
935 int ModApiMainMenu::l_get_max_supp_proto(lua_State *L)
937 lua_pushinteger(L, CLIENT_PROTOCOL_VERSION_MAX);
941 /******************************************************************************/
942 int ModApiMainMenu::l_do_async_callback(lua_State *L)
944 GUIEngine* engine = getGuiEngine(L);
946 size_t func_length, param_length;
947 const char* serialized_func_raw = luaL_checklstring(L, 1, &func_length);
949 const char* serialized_param_raw = luaL_checklstring(L, 2, ¶m_length);
951 sanity_check(serialized_func_raw != NULL);
952 sanity_check(serialized_param_raw != NULL);
954 std::string serialized_func = std::string(serialized_func_raw, func_length);
955 std::string serialized_param = std::string(serialized_param_raw, param_length);
957 lua_pushinteger(L, engine->queueAsync(serialized_func, serialized_param));
962 /******************************************************************************/
963 void ModApiMainMenu::Initialize(lua_State *L, int top)
965 API_FCT(update_formspec);
967 API_FCT(get_textlist_index);
968 API_FCT(get_table_index);
973 API_FCT(get_favorites);
974 API_FCT(show_keys_menu);
975 API_FCT(create_world);
976 API_FCT(delete_world);
977 API_FCT(delete_favorite);
978 API_FCT(set_background);
979 API_FCT(set_topleft_text);
980 API_FCT(get_mapgen_names);
981 API_FCT(get_modpath);
982 API_FCT(get_clientmodpath);
983 API_FCT(get_gamepath);
984 API_FCT(get_texturepath);
985 API_FCT(get_texturepath_share);
989 API_FCT(extract_zip);
990 API_FCT(get_mainmenu_path);
991 API_FCT(show_path_select_dialog);
992 API_FCT(download_file);
994 API_FCT(get_video_drivers);
995 API_FCT(get_video_modes);
996 API_FCT(get_screen_info);
997 API_FCT(get_min_supp_proto);
998 API_FCT(get_max_supp_proto);
999 API_FCT(do_async_callback);
1002 /******************************************************************************/
1003 void ModApiMainMenu::InitializeAsync(lua_State *L, int top)
1006 API_FCT(get_worlds);
1008 API_FCT(get_favorites);
1009 API_FCT(get_mapgen_names);
1010 API_FCT(get_modpath);
1011 API_FCT(get_clientmodpath);
1012 API_FCT(get_gamepath);
1013 API_FCT(get_texturepath);
1014 API_FCT(get_texturepath_share);
1015 API_FCT(create_dir);
1016 API_FCT(delete_dir);
1018 //API_FCT(extract_zip); //TODO remove dependency to GuiEngine
1019 API_FCT(download_file);
1020 //API_FCT(gettext); (gettext lib isn't threadsafe)