diff options
author | Andrew Ward <rw@rubenwardy.com> | 2018-03-28 22:14:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-28 22:14:16 +0100 |
commit | 71b2570f0919d3bb5575c9ec694ecd004222fcea (patch) | |
tree | f3f85d185dde66ab294abb1c15e349ad3b33e818 /src/script/lua_api | |
parent | dfc81983491417c5cd1c99d7db05e421c409379d (diff) | |
download | minetest-71b2570f0919d3bb5575c9ec694ecd004222fcea.tar.gz minetest-71b2570f0919d3bb5575c9ec694ecd004222fcea.tar.bz2 minetest-71b2570f0919d3bb5575c9ec694ecd004222fcea.zip |
Load dependencies and description from mod.conf
Diffstat (limited to 'src/script/lua_api')
-rw-r--r-- | src/script/lua_api/l_mainmenu.cpp | 148 | ||||
-rw-r--r-- | src/script/lua_api/l_mainmenu.h | 8 |
2 files changed, 104 insertions, 52 deletions
diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 95696bc20..027b7b0f8 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -258,56 +258,6 @@ int ModApiMainMenu::l_get_worlds(lua_State *L) } /******************************************************************************/ -int ModApiMainMenu::l_get_games(lua_State *L) -{ - std::vector<SubgameSpec> games = getAvailableGames(); - - lua_newtable(L); - int top = lua_gettop(L); - unsigned int index = 1; - - for (const SubgameSpec &game : games) { - lua_pushnumber(L,index); - lua_newtable(L); - int top_lvl2 = lua_gettop(L); - - lua_pushstring(L,"id"); - lua_pushstring(L, game.id.c_str()); - lua_settable(L, top_lvl2); - - lua_pushstring(L,"path"); - lua_pushstring(L, game.path.c_str()); - lua_settable(L, top_lvl2); - - lua_pushstring(L,"gamemods_path"); - lua_pushstring(L, game.gamemods_path.c_str()); - lua_settable(L, top_lvl2); - - lua_pushstring(L,"name"); - lua_pushstring(L, game.name.c_str()); - lua_settable(L, top_lvl2); - - lua_pushstring(L,"menuicon_path"); - lua_pushstring(L, game.menuicon_path.c_str()); - lua_settable(L, top_lvl2); - - lua_pushstring(L,"addon_mods_paths"); - lua_newtable(L); - int table2 = lua_gettop(L); - int internal_index=1; - for (const std::string &addon_mods_path : game.addon_mods_paths) { - lua_pushnumber(L,internal_index); - lua_pushstring(L, addon_mods_path.c_str()); - lua_settable(L, table2); - internal_index++; - } - lua_settable(L, top_lvl2); - lua_settable(L, top); - index++; - } - return 1; -} -/******************************************************************************/ int ModApiMainMenu::l_get_favorites(lua_State *L) { std::string listtype = "local"; @@ -478,6 +428,103 @@ int ModApiMainMenu::l_delete_favorite(lua_State *L) } /******************************************************************************/ +int ModApiMainMenu::l_get_games(lua_State *L) +{ + std::vector<SubgameSpec> games = getAvailableGames(); + + lua_newtable(L); + int top = lua_gettop(L); + unsigned int index = 1; + + for (const SubgameSpec &game : games) { + lua_pushnumber(L, index); + lua_newtable(L); + int top_lvl2 = lua_gettop(L); + + lua_pushstring(L, "id"); + lua_pushstring(L, game.id.c_str()); + lua_settable(L, top_lvl2); + + lua_pushstring(L, "path"); + lua_pushstring(L, game.path.c_str()); + lua_settable(L, top_lvl2); + + lua_pushstring(L, "gamemods_path"); + lua_pushstring(L, game.gamemods_path.c_str()); + lua_settable(L, top_lvl2); + + lua_pushstring(L, "name"); + lua_pushstring(L, game.name.c_str()); + lua_settable(L, top_lvl2); + + lua_pushstring(L, "menuicon_path"); + lua_pushstring(L, game.menuicon_path.c_str()); + lua_settable(L, top_lvl2); + + lua_pushstring(L, "addon_mods_paths"); + lua_newtable(L); + int table2 = lua_gettop(L); + int internal_index = 1; + for (const std::string &addon_mods_path : game.addon_mods_paths) { + lua_pushnumber(L, internal_index); + lua_pushstring(L, addon_mods_path.c_str()); + lua_settable(L, table2); + internal_index++; + } + lua_settable(L, top_lvl2); + lua_settable(L, top); + index++; + } + return 1; +} + +/******************************************************************************/ +int ModApiMainMenu::l_get_mod_info(lua_State *L) +{ + std::string path = luaL_checkstring(L, 1); + + ModSpec spec; + spec.path = path; + parseModContents(spec); + + lua_newtable(L); + + lua_pushstring(L, spec.name.c_str()); + lua_setfield(L, -2, "name"); + + lua_pushstring(L, spec.is_modpack ? "modpack" : "mod"); + lua_setfield(L, -2, "type"); + + lua_pushstring(L, spec.desc.c_str()); + lua_setfield(L, -2, "description"); + + lua_pushstring(L, spec.path.c_str()); + lua_setfield(L, -2, "path"); + + // Dependencies + lua_newtable(L); + int i = 1; + for (const auto &dep : spec.depends) { + lua_pushstring(L, dep.c_str()); + lua_rawseti(L, -2, i); + i++; + } + lua_setfield(L, -2, "depends"); + + // Optional Dependencies + lua_newtable(L); + i = 1; + for (const auto &dep : spec.optdepends) { + lua_pushstring(L, dep.c_str()); + lua_rawseti(L, -2, i); + i++; + } + lua_setfield(L, -2, "optional_depends"); + + return 1; +} + +/******************************************************************************/ int ModApiMainMenu::l_show_keys_menu(lua_State *L) { GUIEngine* engine = getGuiEngine(L); @@ -968,6 +1015,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top) API_FCT(get_table_index); API_FCT(get_worlds); API_FCT(get_games); + API_FCT(get_mod_info); API_FCT(start); API_FCT(close); API_FCT(get_favorites); diff --git a/src/script/lua_api/l_mainmenu.h b/src/script/lua_api/l_mainmenu.h index ffaab7dca..2faeaf63e 100644 --- a/src/script/lua_api/l_mainmenu.h +++ b/src/script/lua_api/l_mainmenu.h @@ -71,8 +71,6 @@ private: static int l_get_worlds(lua_State *L); - 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); @@ -81,6 +79,12 @@ private: static int l_gettext(lua_State *L); + //packages + + static int l_get_games(lua_State *L); + + static int l_get_mod_info(lua_State *L); + //gui static int l_show_keys_menu(lua_State *L); |