Skip to content

Commit 7607b0a

Browse files
ShadowNinjasofar
authored andcommittedNov 1, 2016
Add version API
1 parent 70e2df4 commit 7607b0a

File tree

6 files changed

+45
-12
lines changed

6 files changed

+45
-12
lines changed
 

Diff for: ‎builtin/mainmenu/tab_credits.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ return {
7676
caption = fgettext("Credits"),
7777
cbf_formspec = function(tabview, name, tabdata)
7878
local logofile = defaulttexturedir .. "logo.png"
79+
local version = core.get_version()
7980
return "image[0.5,1;" .. core.formspec_escape(logofile) .. "]" ..
80-
"label[0.5,3.2;Minetest " .. core.get_version() .. "]" ..
81+
"label[0.5,3.2;" .. version.project .. " " .. version.string .. "]" ..
8182
"label[0.5,3.5;http://minetest.net]" ..
8283
"tablecolumns[color;text]" ..
8384
"tableoptions[background=#00000000;highlight=#00000000;border=false]" ..

Diff for: ‎doc/lua_api.txt

+11
Original file line numberDiff line numberDiff line change
@@ -1908,6 +1908,17 @@ Helper functions
19081908
* nil: return all entries,
19091909
* true: return only subdirectory names, or
19101910
* false: return only file names.
1911+
* `minetest.get_version()`: returns a table containing components of the
1912+
engine version. Components:
1913+
* `project`: Name of the project, eg, "Minetest"
1914+
* `string`: Simple version, eg, "1.2.3-dev"
1915+
* `hash`: Full git version (only set if available), eg, "1.2.3-dev-01234567-dirty"
1916+
Use this for informational purposes only. The information in the returned
1917+
table does not represent the capabilities of the engine, nor is it
1918+
reliable or verifyable. Compatible forks will have a different name and
1919+
version entirely. To check for the presence of engine features, test
1920+
whether the functions exported by the wanted features exist. For example:
1921+
`if core.nodeupdate then ... end`.
19111922

19121923
### Logging
19131924
* `minetest.debug(...)`

Diff for: ‎src/script/lua_api/l_mainmenu.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -955,13 +955,6 @@ int ModApiMainMenu::l_show_file_open_dialog(lua_State *L)
955955
return 0;
956956
}
957957

958-
/******************************************************************************/
959-
int ModApiMainMenu::l_get_version(lua_State *L)
960-
{
961-
lua_pushstring(L, g_version_string);
962-
return 1;
963-
}
964-
965958
/******************************************************************************/
966959
int ModApiMainMenu::l_sound_play(lua_State *L)
967960
{
@@ -1157,7 +1150,6 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
11571150
API_FCT(extract_zip);
11581151
API_FCT(get_mainmenu_path);
11591152
API_FCT(show_file_open_dialog);
1160-
API_FCT(get_version);
11611153
API_FCT(download_file);
11621154
API_FCT(get_modstore_details);
11631155
API_FCT(get_modstore_list);
@@ -1188,7 +1180,6 @@ void ModApiMainMenu::InitializeAsync(AsyncEngine& engine)
11881180
ASYNC_API_FCT(delete_dir);
11891181
ASYNC_API_FCT(copy_dir);
11901182
//ASYNC_API_FCT(extract_zip); //TODO remove dependency to GuiEngine
1191-
ASYNC_API_FCT(get_version);
11921183
ASYNC_API_FCT(download_file);
11931184
ASYNC_API_FCT(get_modstore_details);
11941185
ASYNC_API_FCT(get_modstore_list);

Diff for: ‎src/script/lua_api/l_mainmenu.h

-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ class ModApiMainMenu : public ModApiBase {
7979

8080
static int l_delete_favorite(lua_State *L);
8181

82-
static int l_get_version(lua_State *L);
83-
8482
static int l_sound_play(lua_State *L);
8583

8684
static int l_sound_stop(lua_State *L);

Diff for: ‎src/script/lua_api/l_util.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3333
#include "settings.h"
3434
#include "util/auth.h"
3535
#include "util/base64.h"
36+
#include "config.h"
37+
#include "version.h"
3638
#include <algorithm>
3739

40+
3841
// log([level,] text)
3942
// Writes a line to the logger.
4043
// The one-argument version logs to infostream.
@@ -302,12 +305,14 @@ int ModApiUtil::l_is_yes(lua_State *L)
302305
return 1;
303306
}
304307

308+
// get_builtin_path()
305309
int ModApiUtil::l_get_builtin_path(lua_State *L)
306310
{
307311
NO_MAP_LOCK_REQUIRED;
308312

309313
std::string path = porting::path_share + DIR_DELIM + "builtin";
310314
lua_pushstring(L, path.c_str());
315+
311316
return 1;
312317
}
313318

@@ -460,6 +465,26 @@ int ModApiUtil::l_request_insecure_environment(lua_State *L)
460465
return 1;
461466
}
462467

468+
// get_version()
469+
int ModApiUtil::l_get_version(lua_State *L)
470+
{
471+
lua_createtable(L, 0, 3);
472+
int table = lua_gettop(L);
473+
474+
lua_pushstring(L, PROJECT_NAME_C);
475+
lua_setfield(L, table, "project");
476+
477+
lua_pushstring(L, g_version_string);
478+
lua_setfield(L, table, "string");
479+
480+
if (strcmp(g_version_string, g_version_hash)) {
481+
lua_pushstring(L, g_version_hash);
482+
lua_setfield(L, table, "hash");
483+
}
484+
485+
return 1;
486+
}
487+
463488

464489
void ModApiUtil::Initialize(lua_State *L, int top)
465490
{
@@ -496,6 +521,8 @@ void ModApiUtil::Initialize(lua_State *L, int top)
496521

497522
API_FCT(encode_base64);
498523
API_FCT(decode_base64);
524+
525+
API_FCT(get_version);
499526
}
500527

501528
void ModApiUtil::InitializeAsync(AsyncEngine& engine)
@@ -525,5 +552,7 @@ void ModApiUtil::InitializeAsync(AsyncEngine& engine)
525552

526553
ASYNC_API_FCT(encode_base64);
527554
ASYNC_API_FCT(decode_base64);
555+
556+
ASYNC_API_FCT(get_version);
528557
}
529558

Diff for: ‎src/script/lua_api/l_util.h

+3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ class ModApiUtil : public ModApiBase {
104104
// decode_base64(string)
105105
static int l_decode_base64(lua_State *L);
106106

107+
// get_version()
108+
static int l_get_version(lua_State *L);
109+
107110
public:
108111
static void Initialize(lua_State *L, int top);
109112

0 commit comments

Comments
 (0)