summaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_util.cpp
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2014-05-06 22:31:35 -0400
committerAuke Kok <sofar+github@foo-projects.org>2016-10-31 21:53:00 -0700
commit7607b0ac2065a50a9b68b22909ab40738f2d08e8 (patch)
tree5c806ccbe408463890342599b675b492d63c5162 /src/script/lua_api/l_util.cpp
parent70e2df4f86cf4101a10c7e1f7a6ac5cc03992793 (diff)
downloadminetest-7607b0ac2065a50a9b68b22909ab40738f2d08e8.tar.gz
minetest-7607b0ac2065a50a9b68b22909ab40738f2d08e8.tar.bz2
minetest-7607b0ac2065a50a9b68b22909ab40738f2d08e8.zip
Add version API
Diffstat (limited to 'src/script/lua_api/l_util.cpp')
-rw-r--r--src/script/lua_api/l_util.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp
index fa2d15b03..818c1aeeb 100644
--- a/src/script/lua_api/l_util.cpp
+++ b/src/script/lua_api/l_util.cpp
@@ -33,8 +33,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "settings.h"
#include "util/auth.h"
#include "util/base64.h"
+#include "config.h"
+#include "version.h"
#include <algorithm>
+
// log([level,] text)
// Writes a line to the logger.
// The one-argument version logs to infostream.
@@ -302,12 +305,14 @@ int ModApiUtil::l_is_yes(lua_State *L)
return 1;
}
+// get_builtin_path()
int ModApiUtil::l_get_builtin_path(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
std::string path = porting::path_share + DIR_DELIM + "builtin";
lua_pushstring(L, path.c_str());
+
return 1;
}
@@ -460,6 +465,26 @@ int ModApiUtil::l_request_insecure_environment(lua_State *L)
return 1;
}
+// get_version()
+int ModApiUtil::l_get_version(lua_State *L)
+{
+ lua_createtable(L, 0, 3);
+ int table = lua_gettop(L);
+
+ lua_pushstring(L, PROJECT_NAME_C);
+ lua_setfield(L, table, "project");
+
+ lua_pushstring(L, g_version_string);
+ lua_setfield(L, table, "string");
+
+ if (strcmp(g_version_string, g_version_hash)) {
+ lua_pushstring(L, g_version_hash);
+ lua_setfield(L, table, "hash");
+ }
+
+ return 1;
+}
+
void ModApiUtil::Initialize(lua_State *L, int top)
{
@@ -496,6 +521,8 @@ void ModApiUtil::Initialize(lua_State *L, int top)
API_FCT(encode_base64);
API_FCT(decode_base64);
+
+ API_FCT(get_version);
}
void ModApiUtil::InitializeAsync(AsyncEngine& engine)
@@ -525,5 +552,7 @@ void ModApiUtil::InitializeAsync(AsyncEngine& engine)
ASYNC_API_FCT(encode_base64);
ASYNC_API_FCT(decode_base64);
+
+ ASYNC_API_FCT(get_version);
}