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"
31 #include "convert_json.h"
32 #include "content/content.h"
33 #include "content/subgames.h"
34 #include "serverlist.h"
35 #include "mapgen/mapgen.h"
38 #include <IFileArchive.h>
39 #include <IFileSystem.h>
40 #include "client/renderingengine.h"
41 #include "network/networkprotocol.h"
44 /******************************************************************************/
45 std::string ModApiMainMenu::getTextData(lua_State *L, std::string name)
47 lua_getglobal(L, "gamedata");
49 lua_getfield(L, -1, name.c_str());
54 return luaL_checkstring(L, -1);
57 /******************************************************************************/
58 int ModApiMainMenu::getIntegerData(lua_State *L, std::string name,bool& valid)
60 lua_getglobal(L, "gamedata");
62 lua_getfield(L, -1, name.c_str());
64 if(lua_isnil(L, -1)) {
70 return luaL_checkinteger(L, -1);
73 /******************************************************************************/
74 int ModApiMainMenu::getBoolData(lua_State *L, std::string name,bool& valid)
76 lua_getglobal(L, "gamedata");
78 lua_getfield(L, -1, name.c_str());
80 if(lua_isnil(L, -1)) {
86 return readParam<bool>(L, -1);
89 /******************************************************************************/
90 int ModApiMainMenu::l_update_formspec(lua_State *L)
92 GUIEngine* engine = getGuiEngine(L);
93 sanity_check(engine != NULL);
95 if (engine->m_startgame)
99 std::string formspec(luaL_checkstring(L, 1));
101 if (engine->m_formspecgui != 0) {
102 engine->m_formspecgui->setForm(formspec);
108 /******************************************************************************/
109 int ModApiMainMenu::l_set_formspec_prepend(lua_State *L)
111 GUIEngine *engine = getGuiEngine(L);
112 sanity_check(engine != NULL);
114 if (engine->m_startgame)
117 std::string formspec(luaL_checkstring(L, 1));
118 engine->setFormspecPrepend(formspec);
123 /******************************************************************************/
124 int ModApiMainMenu::l_start(lua_State *L)
126 GUIEngine* engine = getGuiEngine(L);
127 sanity_check(engine != NULL);
129 //update c++ gamedata from lua table
133 MainMenuData *data = engine->m_data;
135 data->selected_world = getIntegerData(L, "selected_world",valid) -1;
136 data->simple_singleplayer_mode = getBoolData(L,"singleplayer",valid);
137 data->do_reconnect = getBoolData(L, "do_reconnect", valid);
138 if (!data->do_reconnect) {
139 data->name = getTextData(L,"playername");
140 data->password = getTextData(L,"password");
141 data->address = getTextData(L,"address");
142 data->port = getTextData(L,"port");
144 data->serverdescription = getTextData(L,"serverdescription");
145 data->servername = getTextData(L,"servername");
147 //close menu next time
148 engine->m_startgame = true;
152 /******************************************************************************/
153 int ModApiMainMenu::l_close(lua_State *L)
155 GUIEngine* engine = getGuiEngine(L);
156 sanity_check(engine != NULL);
158 engine->m_kill = true;
162 /******************************************************************************/
163 int ModApiMainMenu::l_set_background(lua_State *L)
165 GUIEngine* engine = getGuiEngine(L);
166 sanity_check(engine != NULL);
168 std::string backgroundlevel(luaL_checkstring(L, 1));
169 std::string texturename(luaL_checkstring(L, 2));
171 bool tile_image = false;
173 unsigned int minsize = 16;
175 if (!lua_isnone(L, 3)) {
176 tile_image = readParam<bool>(L, 3);
179 if (!lua_isnone(L, 4)) {
180 minsize = lua_tonumber(L, 4);
183 if (backgroundlevel == "background") {
184 retval |= engine->setTexture(TEX_LAYER_BACKGROUND, texturename,
185 tile_image, minsize);
188 if (backgroundlevel == "overlay") {
189 retval |= engine->setTexture(TEX_LAYER_OVERLAY, texturename,
190 tile_image, minsize);
193 if (backgroundlevel == "header") {
194 retval |= engine->setTexture(TEX_LAYER_HEADER, texturename,
195 tile_image, minsize);
198 if (backgroundlevel == "footer") {
199 retval |= engine->setTexture(TEX_LAYER_FOOTER, texturename,
200 tile_image, minsize);
203 lua_pushboolean(L,retval);
207 /******************************************************************************/
208 int ModApiMainMenu::l_set_clouds(lua_State *L)
210 GUIEngine* engine = getGuiEngine(L);
211 sanity_check(engine != NULL);
213 bool value = readParam<bool>(L,1);
215 engine->m_clouds_enabled = value;
220 /******************************************************************************/
221 int ModApiMainMenu::l_get_textlist_index(lua_State *L)
223 // get_table_index accepts both tables and textlists
224 return l_get_table_index(L);
227 /******************************************************************************/
228 int ModApiMainMenu::l_get_table_index(lua_State *L)
230 GUIEngine* engine = getGuiEngine(L);
231 sanity_check(engine != NULL);
233 std::string tablename(luaL_checkstring(L, 1));
234 GUITable *table = engine->m_menu->getTable(tablename);
235 s32 selection = table ? table->getSelected() : 0;
238 lua_pushinteger(L, selection);
244 /******************************************************************************/
245 int ModApiMainMenu::l_get_worlds(lua_State *L)
247 std::vector<WorldSpec> worlds = getAvailableWorlds();
250 int top = lua_gettop(L);
251 unsigned int index = 1;
253 for (const WorldSpec &world : worlds) {
254 lua_pushnumber(L,index);
257 int top_lvl2 = lua_gettop(L);
259 lua_pushstring(L,"path");
260 lua_pushstring(L, world.path.c_str());
261 lua_settable(L, top_lvl2);
263 lua_pushstring(L,"name");
264 lua_pushstring(L, world.name.c_str());
265 lua_settable(L, top_lvl2);
267 lua_pushstring(L,"gameid");
268 lua_pushstring(L, world.gameid.c_str());
269 lua_settable(L, top_lvl2);
271 lua_settable(L, top);
277 /******************************************************************************/
278 int ModApiMainMenu::l_get_games(lua_State *L)
280 std::vector<SubgameSpec> games = getAvailableGames();
283 int top = lua_gettop(L);
284 unsigned int index = 1;
286 for (const SubgameSpec &game : games) {
287 lua_pushnumber(L, index);
289 int top_lvl2 = lua_gettop(L);
291 lua_pushstring(L, "id");
292 lua_pushstring(L, game.id.c_str());
293 lua_settable(L, top_lvl2);
295 lua_pushstring(L, "path");
296 lua_pushstring(L, game.path.c_str());
297 lua_settable(L, top_lvl2);
299 lua_pushstring(L, "type");
300 lua_pushstring(L, "game");
301 lua_settable(L, top_lvl2);
303 lua_pushstring(L, "gamemods_path");
304 lua_pushstring(L, game.gamemods_path.c_str());
305 lua_settable(L, top_lvl2);
307 lua_pushstring(L, "name");
308 lua_pushstring(L, game.name.c_str());
309 lua_settable(L, top_lvl2);
311 lua_pushstring(L, "author");
312 lua_pushstring(L, game.author.c_str());
313 lua_settable(L, top_lvl2);
315 lua_pushstring(L, "release");
316 lua_pushinteger(L, game.release);
317 lua_settable(L, top_lvl2);
319 lua_pushstring(L, "menuicon_path");
320 lua_pushstring(L, game.menuicon_path.c_str());
321 lua_settable(L, top_lvl2);
323 lua_pushstring(L, "addon_mods_paths");
325 int table2 = lua_gettop(L);
326 int internal_index = 1;
327 for (const std::string &addon_mods_path : game.addon_mods_paths) {
328 lua_pushnumber(L, internal_index);
329 lua_pushstring(L, addon_mods_path.c_str());
330 lua_settable(L, table2);
333 lua_settable(L, top_lvl2);
334 lua_settable(L, top);
340 /******************************************************************************/
341 int ModApiMainMenu::l_get_content_info(lua_State *L)
343 std::string path = luaL_checkstring(L, 1);
347 parseContentInfo(spec);
351 lua_pushstring(L, spec.name.c_str());
352 lua_setfield(L, -2, "name");
354 lua_pushstring(L, spec.type.c_str());
355 lua_setfield(L, -2, "type");
357 lua_pushstring(L, spec.author.c_str());
358 lua_setfield(L, -2, "author");
360 lua_pushinteger(L, spec.release);
361 lua_setfield(L, -2, "release");
363 lua_pushstring(L, spec.desc.c_str());
364 lua_setfield(L, -2, "description");
366 lua_pushstring(L, spec.path.c_str());
367 lua_setfield(L, -2, "path");
369 if (spec.type == "mod") {
372 parseModContents(spec);
377 for (const auto &dep : spec.depends) {
378 lua_pushstring(L, dep.c_str());
379 lua_rawseti(L, -2, i++);
381 lua_setfield(L, -2, "depends");
383 // Optional Dependencies
386 for (const auto &dep : spec.optdepends) {
387 lua_pushstring(L, dep.c_str());
388 lua_rawseti(L, -2, i++);
390 lua_setfield(L, -2, "optional_depends");
396 /******************************************************************************/
397 int ModApiMainMenu::l_show_keys_menu(lua_State *L)
399 GUIEngine* engine = getGuiEngine(L);
400 sanity_check(engine != NULL);
402 GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(RenderingEngine::get_gui_env(),
405 engine->m_menumanager,
406 engine->m_texture_source);
411 /******************************************************************************/
412 int ModApiMainMenu::l_create_world(lua_State *L)
414 const char *name = luaL_checkstring(L, 1);
415 int gameidx = luaL_checkinteger(L,2) -1;
417 std::string path = porting::path_user + DIR_DELIM
419 + sanitizeDirName(name, "world_");
421 std::vector<SubgameSpec> games = getAvailableGames();
423 if ((gameidx >= 0) &&
424 (gameidx < (int) games.size())) {
426 // Create world if it doesn't exist
428 loadGameConfAndInitWorld(path, name, games[gameidx], true);
430 } catch (const BaseException &e) {
431 lua_pushstring(L, (std::string("Failed to initialize world: ") + e.what()).c_str());
434 lua_pushstring(L, "Invalid game index");
439 /******************************************************************************/
440 int ModApiMainMenu::l_delete_world(lua_State *L)
442 int world_id = luaL_checkinteger(L, 1) - 1;
443 std::vector<WorldSpec> worlds = getAvailableWorlds();
444 if (world_id < 0 || world_id >= (int) worlds.size()) {
445 lua_pushstring(L, "Invalid world index");
448 const WorldSpec &spec = worlds[world_id];
449 if (!fs::RecursiveDelete(spec.path)) {
450 lua_pushstring(L, "Failed to delete world");
456 /******************************************************************************/
457 int ModApiMainMenu::l_set_topleft_text(lua_State *L)
459 GUIEngine* engine = getGuiEngine(L);
460 sanity_check(engine != NULL);
464 if (!lua_isnone(L,1) && !lua_isnil(L,1))
465 text = luaL_checkstring(L, 1);
467 engine->setTopleftText(text);
471 /******************************************************************************/
472 int ModApiMainMenu::l_get_mapgen_names(lua_State *L)
474 std::vector<const char *> names;
475 bool include_hidden = lua_isboolean(L, 1) && readParam<bool>(L, 1);
476 Mapgen::getMapgenNames(&names, include_hidden);
479 for (size_t i = 0; i != names.size(); i++) {
480 lua_pushstring(L, names[i]);
481 lua_rawseti(L, -2, i + 1);
488 /******************************************************************************/
489 int ModApiMainMenu::l_get_user_path(lua_State *L)
491 std::string path = fs::RemoveRelativePathComponents(porting::path_user);
492 lua_pushstring(L, path.c_str());
496 /******************************************************************************/
497 int ModApiMainMenu::l_get_modpath(lua_State *L)
499 std::string modpath = fs::RemoveRelativePathComponents(
500 porting::path_user + DIR_DELIM + "mods" + DIR_DELIM);
501 lua_pushstring(L, modpath.c_str());
505 /******************************************************************************/
506 int ModApiMainMenu::l_get_clientmodpath(lua_State *L)
508 std::string modpath = fs::RemoveRelativePathComponents(
509 porting::path_user + DIR_DELIM + "clientmods" + DIR_DELIM);
510 lua_pushstring(L, modpath.c_str());
514 /******************************************************************************/
515 int ModApiMainMenu::l_get_gamepath(lua_State *L)
517 std::string gamepath = fs::RemoveRelativePathComponents(
518 porting::path_user + DIR_DELIM + "games" + DIR_DELIM);
519 lua_pushstring(L, gamepath.c_str());
523 /******************************************************************************/
524 int ModApiMainMenu::l_get_texturepath(lua_State *L)
526 std::string gamepath = fs::RemoveRelativePathComponents(
527 porting::path_user + DIR_DELIM + "textures");
528 lua_pushstring(L, gamepath.c_str());
532 /******************************************************************************/
533 int ModApiMainMenu::l_get_texturepath_share(lua_State *L)
535 std::string gamepath = fs::RemoveRelativePathComponents(
536 porting::path_share + DIR_DELIM + "textures");
537 lua_pushstring(L, gamepath.c_str());
541 /******************************************************************************/
542 int ModApiMainMenu::l_get_cache_path(lua_State *L)
544 lua_pushstring(L, fs::RemoveRelativePathComponents(porting::path_cache).c_str());
548 /******************************************************************************/
549 int ModApiMainMenu::l_get_temp_path(lua_State *L)
551 lua_pushstring(L, fs::TempPath().c_str());
555 /******************************************************************************/
556 int ModApiMainMenu::l_create_dir(lua_State *L) {
557 const char *path = luaL_checkstring(L, 1);
559 if (ModApiMainMenu::mayModifyPath(path)) {
560 lua_pushboolean(L, fs::CreateAllDirs(path));
564 lua_pushboolean(L, false);
568 /******************************************************************************/
569 int ModApiMainMenu::l_delete_dir(lua_State *L)
571 const char *path = luaL_checkstring(L, 1);
573 std::string absolute_path = fs::RemoveRelativePathComponents(path);
575 if (ModApiMainMenu::mayModifyPath(absolute_path)) {
576 lua_pushboolean(L, fs::RecursiveDelete(absolute_path));
580 lua_pushboolean(L, false);
584 /******************************************************************************/
585 int ModApiMainMenu::l_copy_dir(lua_State *L)
587 const char *source = luaL_checkstring(L, 1);
588 const char *destination = luaL_checkstring(L, 2);
590 bool keep_source = true;
592 if ((!lua_isnone(L,3)) &&
594 keep_source = readParam<bool>(L,3);
597 std::string absolute_destination = fs::RemoveRelativePathComponents(destination);
598 std::string absolute_source = fs::RemoveRelativePathComponents(source);
600 if ((ModApiMainMenu::mayModifyPath(absolute_destination))) {
601 bool retval = fs::CopyDir(absolute_source,absolute_destination);
603 if (retval && (!keep_source)) {
605 retval &= fs::RecursiveDelete(absolute_source);
607 lua_pushboolean(L,retval);
610 lua_pushboolean(L,false);
614 /******************************************************************************/
615 int ModApiMainMenu::l_is_dir(lua_State *L)
617 const char *path = luaL_checkstring(L, 1);
619 lua_pushboolean(L, fs::IsDir(path));
623 /******************************************************************************/
624 int ModApiMainMenu::l_extract_zip(lua_State *L)
626 const char *zipfile = luaL_checkstring(L, 1);
627 const char *destination = luaL_checkstring(L, 2);
629 std::string absolute_destination = fs::RemoveRelativePathComponents(destination);
631 if (ModApiMainMenu::mayModifyPath(absolute_destination)) {
632 fs::CreateAllDirs(absolute_destination);
634 io::IFileSystem *fs = RenderingEngine::get_filesystem();
636 if (!fs->addFileArchive(zipfile, false, false, io::EFAT_ZIP)) {
637 lua_pushboolean(L,false);
641 sanity_check(fs->getFileArchiveCount() > 0);
643 /**********************************************************************/
644 /* WARNING this is not threadsafe!! */
645 /**********************************************************************/
646 io::IFileArchive* opened_zip =
647 fs->getFileArchive(fs->getFileArchiveCount()-1);
649 const io::IFileList* files_in_zip = opened_zip->getFileList();
651 unsigned int number_of_files = files_in_zip->getFileCount();
653 for (unsigned int i=0; i < number_of_files; i++) {
654 std::string fullpath = destination;
655 fullpath += DIR_DELIM;
656 fullpath += files_in_zip->getFullFileName(i).c_str();
657 std::string fullpath_dir = fs::RemoveLastPathComponent(fullpath);
659 if (!files_in_zip->isDirectory(i)) {
660 if (!fs::PathExists(fullpath_dir) && !fs::CreateAllDirs(fullpath_dir)) {
661 fs->removeFileArchive(fs->getFileArchiveCount()-1);
662 lua_pushboolean(L,false);
666 io::IReadFile* toread = opened_zip->createAndOpenFile(i);
668 FILE *targetfile = fopen(fullpath.c_str(),"wb");
670 if (targetfile == NULL) {
671 fs->removeFileArchive(fs->getFileArchiveCount()-1);
672 lua_pushboolean(L,false);
676 char read_buffer[1024];
679 while (total_read < toread->getSize()) {
681 unsigned int bytes_read =
682 toread->read(read_buffer,sizeof(read_buffer));
683 if ((bytes_read == 0 ) ||
684 (fwrite(read_buffer, 1, bytes_read, targetfile) != bytes_read))
687 fs->removeFileArchive(fs->getFileArchiveCount()-1);
688 lua_pushboolean(L,false);
691 total_read += bytes_read;
699 fs->removeFileArchive(fs->getFileArchiveCount()-1);
700 lua_pushboolean(L,true);
704 lua_pushboolean(L,false);
708 /******************************************************************************/
709 int ModApiMainMenu::l_get_mainmenu_path(lua_State *L)
711 GUIEngine* engine = getGuiEngine(L);
712 sanity_check(engine != NULL);
714 lua_pushstring(L,engine->getScriptDir().c_str());
718 /******************************************************************************/
719 bool ModApiMainMenu::mayModifyPath(const std::string &path)
721 if (fs::PathStartsWith(path, fs::TempPath()))
724 if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "games")))
727 if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "mods")))
730 if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "textures")))
733 if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "worlds")))
736 if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_cache)))
743 /******************************************************************************/
744 int ModApiMainMenu::l_may_modify_path(lua_State *L)
746 const char *target = luaL_checkstring(L, 1);
747 std::string absolute_destination = fs::RemoveRelativePathComponents(target);
748 lua_pushboolean(L, ModApiMainMenu::mayModifyPath(absolute_destination));
752 /******************************************************************************/
753 int ModApiMainMenu::l_show_path_select_dialog(lua_State *L)
755 GUIEngine* engine = getGuiEngine(L);
756 sanity_check(engine != NULL);
758 const char *formname= luaL_checkstring(L, 1);
759 const char *title = luaL_checkstring(L, 2);
760 bool is_file_select = readParam<bool>(L, 3);
762 GUIFileSelectMenu* fileOpenMenu =
763 new GUIFileSelectMenu(RenderingEngine::get_gui_env(),
766 engine->m_menumanager,
770 fileOpenMenu->setTextDest(engine->m_buttonhandler);
771 fileOpenMenu->drop();
775 /******************************************************************************/
776 int ModApiMainMenu::l_download_file(lua_State *L)
778 const char *url = luaL_checkstring(L, 1);
779 const char *target = luaL_checkstring(L, 2);
782 std::string absolute_destination = fs::RemoveRelativePathComponents(target);
784 if (ModApiMainMenu::mayModifyPath(absolute_destination)) {
785 if (GUIEngine::downloadFile(url,absolute_destination)) {
786 lua_pushboolean(L,true);
790 errorstream << "DOWNLOAD denied: " << absolute_destination
791 << " isn't a allowed path" << std::endl;
793 lua_pushboolean(L,false);
797 /******************************************************************************/
798 int ModApiMainMenu::l_get_video_drivers(lua_State *L)
800 std::vector<irr::video::E_DRIVER_TYPE> drivers = RenderingEngine::getSupportedVideoDrivers();
803 for (u32 i = 0; i != drivers.size(); i++) {
804 const char *name = RenderingEngine::getVideoDriverName(drivers[i]);
805 const char *fname = RenderingEngine::getVideoDriverFriendlyName(drivers[i]);
808 lua_pushstring(L, name);
809 lua_setfield(L, -2, "name");
810 lua_pushstring(L, fname);
811 lua_setfield(L, -2, "friendly_name");
813 lua_rawseti(L, -2, i + 1);
819 /******************************************************************************/
820 int ModApiMainMenu::l_get_video_modes(lua_State *L)
822 std::vector<core::vector3d<u32> > videomodes
823 = RenderingEngine::getSupportedVideoModes();
826 for (u32 i = 0; i != videomodes.size(); i++) {
828 lua_pushnumber(L, videomodes[i].X);
829 lua_setfield(L, -2, "w");
830 lua_pushnumber(L, videomodes[i].Y);
831 lua_setfield(L, -2, "h");
832 lua_pushnumber(L, videomodes[i].Z);
833 lua_setfield(L, -2, "depth");
835 lua_rawseti(L, -2, i + 1);
841 /******************************************************************************/
842 int ModApiMainMenu::l_gettext(lua_State *L)
844 std::string text = strgettext(std::string(luaL_checkstring(L, 1)));
845 lua_pushstring(L, text.c_str());
850 /******************************************************************************/
851 int ModApiMainMenu::l_get_screen_info(lua_State *L)
854 int top = lua_gettop(L);
855 lua_pushstring(L,"density");
856 lua_pushnumber(L,RenderingEngine::getDisplayDensity());
857 lua_settable(L, top);
859 lua_pushstring(L,"display_width");
860 lua_pushnumber(L,RenderingEngine::getDisplaySize().X);
861 lua_settable(L, top);
863 lua_pushstring(L,"display_height");
864 lua_pushnumber(L,RenderingEngine::getDisplaySize().Y);
865 lua_settable(L, top);
867 const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize();
868 lua_pushstring(L,"window_width");
869 lua_pushnumber(L, window_size.X);
870 lua_settable(L, top);
872 lua_pushstring(L,"window_height");
873 lua_pushnumber(L, window_size.Y);
874 lua_settable(L, top);
878 /******************************************************************************/
879 int ModApiMainMenu::l_get_min_supp_proto(lua_State *L)
881 lua_pushinteger(L, CLIENT_PROTOCOL_VERSION_MIN);
885 int ModApiMainMenu::l_get_max_supp_proto(lua_State *L)
887 lua_pushinteger(L, CLIENT_PROTOCOL_VERSION_MAX);
891 /******************************************************************************/
892 int ModApiMainMenu::l_open_url(lua_State *L)
894 std::string url = luaL_checkstring(L, 1);
895 lua_pushboolean(L, porting::open_url(url));
899 /******************************************************************************/
900 int ModApiMainMenu::l_open_dir(lua_State *L)
902 std::string path = luaL_checkstring(L, 1);
903 lua_pushboolean(L, porting::open_directory(path));
907 /******************************************************************************/
908 int ModApiMainMenu::l_do_async_callback(lua_State *L)
910 GUIEngine* engine = getGuiEngine(L);
912 size_t func_length, param_length;
913 const char* serialized_func_raw = luaL_checklstring(L, 1, &func_length);
915 const char* serialized_param_raw = luaL_checklstring(L, 2, ¶m_length);
917 sanity_check(serialized_func_raw != NULL);
918 sanity_check(serialized_param_raw != NULL);
920 std::string serialized_func = std::string(serialized_func_raw, func_length);
921 std::string serialized_param = std::string(serialized_param_raw, param_length);
923 lua_pushinteger(L, engine->queueAsync(serialized_func, serialized_param));
928 /******************************************************************************/
929 void ModApiMainMenu::Initialize(lua_State *L, int top)
931 API_FCT(update_formspec);
932 API_FCT(set_formspec_prepend);
934 API_FCT(get_textlist_index);
935 API_FCT(get_table_index);
938 API_FCT(get_content_info);
941 API_FCT(show_keys_menu);
942 API_FCT(create_world);
943 API_FCT(delete_world);
944 API_FCT(set_background);
945 API_FCT(set_topleft_text);
946 API_FCT(get_mapgen_names);
947 API_FCT(get_user_path);
948 API_FCT(get_modpath);
949 API_FCT(get_clientmodpath);
950 API_FCT(get_gamepath);
951 API_FCT(get_texturepath);
952 API_FCT(get_texturepath_share);
953 API_FCT(get_cache_path);
954 API_FCT(get_temp_path);
959 API_FCT(extract_zip);
960 API_FCT(may_modify_path);
961 API_FCT(get_mainmenu_path);
962 API_FCT(show_path_select_dialog);
963 API_FCT(download_file);
965 API_FCT(get_video_drivers);
966 API_FCT(get_video_modes);
967 API_FCT(get_screen_info);
968 API_FCT(get_min_supp_proto);
969 API_FCT(get_max_supp_proto);
972 API_FCT(do_async_callback);
975 /******************************************************************************/
976 void ModApiMainMenu::InitializeAsync(lua_State *L, int top)
980 API_FCT(get_mapgen_names);
981 API_FCT(get_user_path);
982 API_FCT(get_modpath);
983 API_FCT(get_clientmodpath);
984 API_FCT(get_gamepath);
985 API_FCT(get_texturepath);
986 API_FCT(get_texturepath_share);
987 API_FCT(get_cache_path);
988 API_FCT(get_temp_path);
993 //API_FCT(extract_zip); //TODO remove dependency to GuiEngine
994 API_FCT(may_modify_path);
995 API_FCT(download_file);
996 API_FCT(get_min_supp_proto);
997 API_FCT(get_max_supp_proto);
998 //API_FCT(gettext); (gettext lib isn't threadsafe)