mirror of
				https://github.com/luanti-org/luanti.git
				synced 2025-11-04 01:05:48 +01:00 
			
		
		
		
	Fix core.get_content_info docs and harden implementation (#15925)
				
					
				
			This commit is contained in:
		@@ -331,7 +331,7 @@ Package - content which is downloadable from the content db, may or may not be i
 | 
			
		||||
      ```lua
 | 
			
		||||
      {
 | 
			
		||||
          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",
 | 
			
		||||
          description      = "description",
 | 
			
		||||
          author           = "author",
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user