Browse Source

Restore API function "get_mod_info"

master
OldCoder 1 year ago
parent
commit
9d9a801f20
3 changed files with 60 additions and 2 deletions
  1. +9
    -0
      doc/menu_lua_api.txt
  2. +49
    -0
      src/script/lua_api/l_mainmenu.cpp
  3. +2
    -2
      src/script/lua_api/l_mainmenu.h

+ 9
- 0
doc/menu_lua_api.txt View File

@@ -125,6 +125,15 @@ core.get_game(index)
core.get_games() -> table of all games in upper format (possible in async calls)
core.get_mapgen_names([include_hidden=false]) -> table of map generator algorithms
registered in the core (possible in async calls)
core.get_mod_info(path)
^ returns {
name = "name of mod",
type = "mod" or "modpack",
description = "description",
path = "path/to/mod",
depends = {"mod", "names"},
optional_depends = {"mod", "names"},
}

Favorites:
core.get_favorites(location) -> list of favorites (possible in async calls)


+ 49
- 0
src/script/lua_api/l_mainmenu.cpp View File

@@ -310,6 +310,54 @@ int ModApiMainMenu::l_get_games(lua_State *L)
}
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_get_favorites(lua_State *L)
{
@@ -974,6 +1022,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);


+ 2
- 2
src/script/lua_api/l_mainmenu.h View File

@@ -80,6 +80,8 @@ private:

static int l_delete_favorite(lua_State *L);

static int l_get_mod_info(lua_State *L);

static int l_gettext(lua_State *L);

//gui
@@ -135,7 +137,6 @@ private:

static int l_get_max_supp_proto(lua_State *L);


// async
static int l_do_async_callback(lua_State *L);

@@ -149,7 +150,6 @@ public:
static void Initialize(lua_State *L, int top);

static void InitializeAsync(lua_State *L, int top);

};

#endif /* L_MAINMENU_H_ */

Loading…
Cancel
Save