aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
authorVincent Robinson <robinsonvincent89@gmail.com>2021-04-23 12:37:24 -0700
committerGitHub <noreply@github.com>2021-04-23 21:37:24 +0200
commit074e6a67def42ab9c91b8638c914869d516a9cd7 (patch)
tree1e8b9e20dc6ee5ef4ce8482bb762b89751538e28 /src/script/lua_api
parent3e2145d662d26443e96ac7191eda093c85c6f2bc (diff)
downloadminetest-074e6a67def42ab9c91b8638c914869d516a9cd7.tar.gz
minetest-074e6a67def42ab9c91b8638c914869d516a9cd7.tar.bz2
minetest-074e6a67def42ab9c91b8638c914869d516a9cd7.zip
Add `minetest.colorspec_to_colorstring` (#10425)
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_util.cpp24
-rw-r--r--src/script/lua_api/l_util.h3
2 files changed, 25 insertions, 2 deletions
diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp
index 203a0dd28..8de2d67c8 100644
--- a/src/script/lua_api/l_util.cpp
+++ b/src/script/lua_api/l_util.cpp
@@ -17,6 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "irrlichttypes_extrabloated.h"
#include "lua_api/l_util.h"
#include "lua_api/l_internal.h"
#include "lua_api/l_settings.h"
@@ -40,7 +41,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/hex.h"
#include "util/sha1.h"
#include <algorithm>
-
+#include <cstdio>
// log([level,] text)
// Writes a line to the logger.
@@ -479,6 +480,23 @@ int ModApiUtil::l_sha1(lua_State *L)
return 1;
}
+// colorspec_to_colorstring(colorspec)
+int ModApiUtil::l_colorspec_to_colorstring(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+
+ video::SColor color(0);
+ if (read_color(L, 1, &color)) {
+ char colorstring[10];
+ snprintf(colorstring, 10, "#%02X%02X%02X%02X",
+ color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
+ lua_pushstring(L, colorstring);
+ return 1;
+ }
+
+ return 0;
+}
+
void ModApiUtil::Initialize(lua_State *L, int top)
{
API_FCT(log);
@@ -513,6 +531,7 @@ void ModApiUtil::Initialize(lua_State *L, int top)
API_FCT(get_version);
API_FCT(sha1);
+ API_FCT(colorspec_to_colorstring);
LuaSettings::create(L, g_settings, g_settings_path);
lua_setfield(L, top, "settings");
@@ -537,6 +556,7 @@ void ModApiUtil::InitializeClient(lua_State *L, int top)
API_FCT(get_version);
API_FCT(sha1);
+ API_FCT(colorspec_to_colorstring);
}
void ModApiUtil::InitializeAsync(lua_State *L, int top)
@@ -564,8 +584,8 @@ void ModApiUtil::InitializeAsync(lua_State *L, int top)
API_FCT(get_version);
API_FCT(sha1);
+ API_FCT(colorspec_to_colorstring);
LuaSettings::create(L, g_settings, g_settings_path);
lua_setfield(L, top, "settings");
}
-
diff --git a/src/script/lua_api/l_util.h b/src/script/lua_api/l_util.h
index dbdd62b99..6943a6afb 100644
--- a/src/script/lua_api/l_util.h
+++ b/src/script/lua_api/l_util.h
@@ -101,6 +101,9 @@ private:
// sha1(string, raw)
static int l_sha1(lua_State *L);
+ // colorspec_to_colorstring(colorspec)
+ static int l_colorspec_to_colorstring(lua_State *L);
+
public:
static void Initialize(lua_State *L, int top);
static void InitializeAsync(lua_State *L, int top);