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
|
@ -30,8 +30,12 @@
|
|||
#include "common/c_converter.h"
|
||||
#include "gui/guiOpenURL.h"
|
||||
#include "gettext.h"
|
||||
#include "log.h"
|
||||
#include "util/string.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
/******************************************************************************/
|
||||
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;
|
||||
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_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_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_setfield(L, -2, "release");
|
||||
|
||||
|
@ -389,8 +396,12 @@ int ModApiMainMenu::l_get_content_info(lua_State *L)
|
|||
if (spec.type == "mod") {
|
||||
ModSpec spec;
|
||||
spec.path = path;
|
||||
// TODO return nothing on failure (needs callers to handle it)
|
||||
static_cast<void>(parseModContents(spec));
|
||||
// Since the content was already determined to be a mod,
|
||||
// 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
|
||||
lua_newtable(L);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue