mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Fix core.get_content_info
docs and harden implementation (#15925)
This commit is contained in:
parent
95d6008332
commit
8fc7bf2af4
2 changed files with 19 additions and 8 deletions
|
@ -331,7 +331,7 @@ Package - content which is downloadable from the content db, may or may not be i
|
||||||
```lua
|
```lua
|
||||||
{
|
{
|
||||||
name = "technical_id",
|
name = "technical_id",
|
||||||
type = "mod" or "modpack" or "game" or "txp",
|
type = "mod" or "modpack" or "game" or "txp" or "unknown",
|
||||||
title = "Human readable title",
|
title = "Human readable title",
|
||||||
description = "description",
|
description = "description",
|
||||||
author = "author",
|
author = "author",
|
||||||
|
|
|
@ -30,8 +30,12 @@
|
||||||
#include "common/c_converter.h"
|
#include "common/c_converter.h"
|
||||||
#include "gui/guiOpenURL.h"
|
#include "gui/guiOpenURL.h"
|
||||||
#include "gettext.h"
|
#include "gettext.h"
|
||||||
|
#include "log.h"
|
||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
std::string ModApiMainMenu::getTextData(lua_State *L, const std::string &name)
|
std::string ModApiMainMenu::getTextData(lua_State *L, const std::string &name)
|
||||||
{
|
{
|
||||||
|
@ -355,6 +359,14 @@ int ModApiMainMenu::l_get_content_info(lua_State *L)
|
||||||
spec.path = path;
|
spec.path = path;
|
||||||
parseContentInfo(spec);
|
parseContentInfo(spec);
|
||||||
|
|
||||||
|
if (spec.type == "unknown") {
|
||||||
|
// In <=5.11.0 the API call was erroneously not documented as
|
||||||
|
// being able to return type "unknown".
|
||||||
|
// TODO inspect call sites and make sure this is handled, then we can
|
||||||
|
// likely remove the warning.
|
||||||
|
warningstream << "Requested content info has type \"unknown\"" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
|
|
||||||
lua_pushstring(L, spec.name.c_str());
|
lua_pushstring(L, spec.name.c_str());
|
||||||
|
@ -369,11 +381,6 @@ int ModApiMainMenu::l_get_content_info(lua_State *L)
|
||||||
lua_pushstring(L, spec.author.c_str());
|
lua_pushstring(L, spec.author.c_str());
|
||||||
lua_setfield(L, -2, "author");
|
lua_setfield(L, -2, "author");
|
||||||
|
|
||||||
if (!spec.title.empty()) {
|
|
||||||
lua_pushstring(L, spec.title.c_str());
|
|
||||||
lua_setfield(L, -2, "title");
|
|
||||||
}
|
|
||||||
|
|
||||||
lua_pushinteger(L, spec.release);
|
lua_pushinteger(L, spec.release);
|
||||||
lua_setfield(L, -2, "release");
|
lua_setfield(L, -2, "release");
|
||||||
|
|
||||||
|
@ -389,8 +396,12 @@ int ModApiMainMenu::l_get_content_info(lua_State *L)
|
||||||
if (spec.type == "mod") {
|
if (spec.type == "mod") {
|
||||||
ModSpec spec;
|
ModSpec spec;
|
||||||
spec.path = path;
|
spec.path = path;
|
||||||
// TODO return nothing on failure (needs callers to handle it)
|
// Since the content was already determined to be a mod,
|
||||||
static_cast<void>(parseModContents(spec));
|
// the parsing is guaranteed to succeed unless the init.lua
|
||||||
|
// file happens to be deleted between the content parse and
|
||||||
|
// the mod parse.
|
||||||
|
[[maybe_unused]] bool success = parseModContents(spec);
|
||||||
|
assert(success);
|
||||||
|
|
||||||
// Dependencies
|
// Dependencies
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue