From ca89e63b27a2548a7615fcf4943c22f88818f6eb Mon Sep 17 00:00:00 2001 From: kwolekr Date: Mon, 29 Dec 2014 21:23:51 -0500 Subject: Add core.get_mapgen_names() to Main Menu API (and use it) Also rewrite mapgen registration for static initialization --- src/script/lua_api/l_mainmenu.cpp | 22 ++++++++++++++++++++++ src/script/lua_api/l_mainmenu.h | 4 +++- 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'src/script') diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 1760d2794..572b8efc8 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "filesys.h" #include "convert_json.h" #include "serverlist.h" +#include "emerge.h" #include "sound.h" #include "settings.h" #include "main.h" // for g_settings @@ -688,6 +689,25 @@ int ModApiMainMenu::l_set_topleft_text(lua_State *L) return 0; } +/******************************************************************************/ +int ModApiMainMenu::l_get_mapgen_names(lua_State *L) +{ + lua_newtable(L); + + std::list names; + EmergeManager::getMapgenNames(names); + + int i = 1; + for (std::list::const_iterator + it = names.begin(); it != names.end(); ++it) { + lua_pushstring(L, *it); + lua_rawseti(L, -2, i++); + } + + return 1; +} + + /******************************************************************************/ int ModApiMainMenu::l_get_modpath(lua_State *L) { @@ -1107,6 +1127,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top) API_FCT(delete_favorite); API_FCT(set_background); API_FCT(set_topleft_text); + API_FCT(get_mapgen_names); API_FCT(get_modpath); API_FCT(get_gamepath); API_FCT(get_texturepath); @@ -1137,6 +1158,7 @@ void ModApiMainMenu::InitializeAsync(AsyncEngine& engine) ASYNC_API_FCT(get_worlds); ASYNC_API_FCT(get_games); ASYNC_API_FCT(get_favorites); + ASYNC_API_FCT(get_mapgen_names); ASYNC_API_FCT(get_modpath); ASYNC_API_FCT(get_gamepath); ASYNC_API_FCT(get_texturepath); diff --git a/src/script/lua_api/l_mainmenu.h b/src/script/lua_api/l_mainmenu.h index 1783a3f7f..ff61dd97a 100644 --- a/src/script/lua_api/l_mainmenu.h +++ b/src/script/lua_api/l_mainmenu.h @@ -73,6 +73,8 @@ private: static int l_get_games(lua_State *L); + static int l_get_mapgen_names(lua_State *L); + static int l_get_favorites(lua_State *L); static int l_delete_favorite(lua_State *L); @@ -112,7 +114,7 @@ private: static int l_get_modpath(lua_State *L); static int l_get_gamepath(lua_State *L); - + static int l_get_texturepath(lua_State *L); static int l_get_texturepath_share(lua_State *L); -- cgit v1.2.3