Skip to content

Commit

Permalink
Add build info and active video_driver, limit debug.txt lines, fix ou…
Browse files Browse the repository at this point in the history
…tdated minetest.conf being read
  • Loading branch information
grorp committed Sep 3, 2023
1 parent 88c5790 commit aea723b
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 24 deletions.
52 changes: 45 additions & 7 deletions builtin/mainmenu/tab_about.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,27 +122,65 @@ end
local function read_text_file(path)
local f = io.open(path, "r")
if not f then
return nil
return "[not available]\n"
end
local text = f:read("*all")
f:close()
return text
end

local function tail(str, num_lines)
local first_char = 1

local str_reversed = str:reverse()
local index = #str
local num_newlines = 0
for char in str_reversed:gmatch(".") do
if char == "\n" then -- catches CRLF as well
num_newlines = num_newlines + 1
end
if num_newlines > num_lines then
first_char = index + 1
break
end
index = index - 1
end

return str:sub(first_char)
end

-- TODO move these unittests somewhere else

local test_str = "123456\n234567\n345678\n456789\n"

assert(tail(test_str, -math.huge) == "")
assert(tail(test_str, -1) == "")
assert(tail(test_str, 0) == "")
assert(tail(test_str, 1) == "456789\n")
assert(tail(test_str, 2) == "345678\n456789\n")
assert(tail(test_str, 3) == "234567\n345678\n456789\n")
assert(tail(test_str, 4) == test_str)
assert(tail(test_str, math.huge) == test_str)

local function collect_debug_info()
local version = core.get_version()
local build_info = core.get_build_info()
local irrlicht_device = core.get_active_irrlicht_device()
local driver = core.get_active_driver()
local renderer = core.get_active_renderer()

local path_prefix = core.get_user_path() .. DIR_DELIM
local minetest_conf = read_text_file(path_prefix .. "minetest.conf") or "[not available]\n"
local debug_txt = read_text_file(path_prefix .. "debug.txt") or "[not available]\n"
-- Write the current settings to "minetest.conf" so we don't read outdated ones.
core.settings:write()
local minetest_conf = read_text_file(path_prefix .. "minetest.conf")
local debug_txt = tail(read_text_file(path_prefix .. "debug.txt"), 64)

return table.concat({
version.project, " ", (version.hash or version.string), "\n",
"Platform: ", PLATFORM, "\n",
"Active Irrlicht device: ", irrlicht_device, "\n",
"Active renderer: ", renderer, "\n\n",
version.project, " ", (version.hash or version.string), " (", PLATFORM, ")\n",
build_info, "\n\n",
"Active Irrlicht device = ", irrlicht_device, "\n",
"Active \"video_driver\" = ", driver, "\n", -- not redundant!
"Active renderer = ", renderer, "\n\n",
"minetest.conf\n",
"-------------\n",
minetest_conf, "\n",
Expand Down
17 changes: 0 additions & 17 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "gui/touchscreengui.h"
#endif

// for version information only
extern "C" {
#if USE_LUAJIT
#include <luajit.h>
#else
#include <lua.h>
#endif
}

#if !defined(__cpp_rtti) || !defined(__cpp_exceptions)
#error Minetest cannot be built without exceptions or RTTI
#endif
Expand Down Expand Up @@ -423,14 +414,6 @@ static void print_version()
{
std::cout << PROJECT_NAME_C " " << g_version_hash
<< " (" << porting::getPlatformName() << ")" << std::endl;
#ifndef SERVER
std::cout << "Using Irrlicht " IRRLICHT_SDK_VERSION << std::endl;
#endif
#if USE_LUAJIT
std::cout << "Using " << LUAJIT_VERSION << std::endl;
#else
std::cout << "Using " << LUA_RELEASE << std::endl;
#endif
std::cout << g_build_info << std::endl;
}

Expand Down
8 changes: 8 additions & 0 deletions src/script/lua_api/l_mainmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,13 @@ int ModApiMainMenu::l_get_active_irrlicht_device(lua_State *L)
return 1;
}

/******************************************************************************/
int ModApiMainMenu::l_get_build_info(lua_State *L)
{
lua_pushstring(L, g_build_info);
return 1;
}

/******************************************************************************/
int ModApiMainMenu::l_get_min_supp_proto(lua_State *L)
{
Expand Down Expand Up @@ -1134,6 +1141,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
API_FCT(get_active_driver);
API_FCT(get_active_renderer);
API_FCT(get_active_irrlicht_device);
API_FCT(get_build_info);
API_FCT(get_min_supp_proto);
API_FCT(get_max_supp_proto);
API_FCT(open_url);
Expand Down
2 changes: 2 additions & 0 deletions src/script/lua_api/l_mainmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class ModApiMainMenu: public ModApiBase

static int l_get_active_irrlicht_device(lua_State *L);

static int l_get_build_info(lua_State *L);

// filesystem

static int l_get_mainmenu_path(lua_State *L);
Expand Down
18 changes: 18 additions & 0 deletions src/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "cmake_config_githash.h"
#endif

// Included for version information.
#include "IrrCompileConfig.h"
extern "C" {
#if USE_LUAJIT
#include <luajit.h>
#else
#include <lua.h>
#endif
}

#ifndef VERSION_GITHASH
#define VERSION_GITHASH VERSION_STRING
#endif
Expand All @@ -34,6 +44,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
const char *g_version_string = VERSION_STRING;
const char *g_version_hash = VERSION_GITHASH;
const char *g_build_info =
#ifndef SERVER
"Using Irrlicht " IRRLICHT_SDK_VERSION "\n"
#endif
#if USE_LUAJIT
"Using " LUAJIT_VERSION "\n"
#else
"Using " LUA_RELEASE "\n"
#endif
"BUILD_TYPE=" BUILD_TYPE "\n"
"RUN_IN_PLACE=" STR(RUN_IN_PLACE) "\n"
"USE_CURL=" STR(USE_CURL) "\n"
Expand Down

0 comments on commit aea723b

Please sign in to comment.