summaryrefslogtreecommitdiffstats
path: root/src/Bindings
diff options
context:
space:
mode:
authornshah25 <68348722+nshah25@users.noreply.github.com>2021-05-03 22:07:09 +0200
committerGitHub <noreply@github.com>2021-05-03 22:07:09 +0200
commit8be1dd54bb17b3ba3e20960aa3c3f696d09facf7 (patch)
tree334cf9a2c9f781816f8278c933d66a71bf5c7d88 /src/Bindings
parentStyle: specify include relativity (#5217) (diff)
downloadcuberite-8be1dd54bb17b3ba3e20960aa3c3f696d09facf7.tar
cuberite-8be1dd54bb17b3ba3e20960aa3c3f696d09facf7.tar.gz
cuberite-8be1dd54bb17b3ba3e20960aa3c3f696d09facf7.tar.bz2
cuberite-8be1dd54bb17b3ba3e20960aa3c3f696d09facf7.tar.lz
cuberite-8be1dd54bb17b3ba3e20960aa3c3f696d09facf7.tar.xz
cuberite-8be1dd54bb17b3ba3e20960aa3c3f696d09facf7.tar.zst
cuberite-8be1dd54bb17b3ba3e20960aa3c3f696d09facf7.zip
Diffstat (limited to 'src/Bindings')
-rw-r--r--src/Bindings/AllToLua.pkg2
-rw-r--r--src/Bindings/LuaState.cpp15
-rw-r--r--src/Bindings/LuaState.h2
-rw-r--r--src/Bindings/ManualBindings.cpp69
4 files changed, 88 insertions, 0 deletions
diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg
index dc25ca379..e6787b70d 100644
--- a/src/Bindings/AllToLua.pkg
+++ b/src/Bindings/AllToLua.pkg
@@ -123,6 +123,8 @@ $cfile "../BlockEntities/MobHeadEntity.h"
$cfile "../BlockEntities/MobSpawnerEntity.h"
$cfile "../BlockEntities/FlowerPotEntity.h"
+// Registries:
+$cfile "../Registries/Statistics.h"
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp
index 8c47ab322..ccd7244fa 100644
--- a/src/Bindings/LuaState.cpp
+++ b/src/Bindings/LuaState.cpp
@@ -1378,6 +1378,21 @@ bool cLuaState::GetStackValue(int a_StackPos, ContiguousByteBuffer & a_Data)
+bool cLuaState::GetStackValue(int a_StackPos, CustomStatistic & a_Value)
+{
+ if (lua_isnumber(m_LuaState, a_StackPos))
+ {
+ a_Value = static_cast<CustomStatistic>(static_cast<std::underlying_type_t<CustomStatistic>>(lua_tonumber(m_LuaState, a_StackPos)));
+ return true;
+ }
+
+ return true;
+}
+
+
+
+
+
bool cLuaState::GetStackValue(int a_StackPos, double & a_ReturnedVal)
{
if (lua_isnumber(m_LuaState, a_StackPos))
diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h
index 0493804e5..f615ef0a6 100644
--- a/src/Bindings/LuaState.h
+++ b/src/Bindings/LuaState.h
@@ -37,6 +37,7 @@ extern "C"
#include "../Defines.h"
#include "../FunctionRef.h"
+#include "../Registries/Statistics.h"
#include "PluginManager.h"
#include "LuaState_Typedefs.inc"
@@ -657,6 +658,7 @@ public:
bool GetStackValue(int a_StackPos, cTrackedRefPtr & a_Ref);
bool GetStackValue(int a_StackPos, cTrackedRefSharedPtr & a_Ref);
bool GetStackValue(int a_StackPos, ContiguousByteBuffer & a_Data);
+ bool GetStackValue(int a_StackPos, CustomStatistic & a_Value);
bool GetStackValue(int a_StackPos, double & a_Value);
bool GetStackValue(int a_StackPos, eBlockFace & a_Value);
bool GetStackValue(int a_StackPos, eWeather & a_Value);
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index cd5e69b22..f06f4da37 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -4348,6 +4348,69 @@ static int tolua_cEntity_GetSpeed(lua_State * tolua_S)
+static int tolua_get_StatisticsManager_Custom(lua_State * tolua_S)
+{
+ // Check the params:
+ cLuaState L(tolua_S);
+ if (!L.CheckParamNumber(2))
+ {
+ return 0;
+ }
+
+ // Get the params:
+ lua_pushstring(tolua_S, ".self");
+ lua_rawget(tolua_S, 1);
+ StatisticsManager * Self = static_cast<StatisticsManager *>(lua_touserdata(tolua_S, -1));
+ CustomStatistic Statistic;
+ if (!L.GetStackValue(2, Statistic))
+ {
+ return L.ApiParamError("Expected a valid custom statistic ID");
+ }
+
+ // Push result if statistic exists:
+ if (const auto Result = Self->Custom.find(Statistic); Result != Self->Custom.end())
+ {
+ L.Push(Result->second);
+ return 1;
+ }
+
+ return 0;
+}
+
+
+
+
+
+static int tolua_set_StatisticsManager_Custom(lua_State * tolua_S)
+{
+ // Check the params:
+ cLuaState L(tolua_S);
+ if (!L.CheckParamNumber(2))
+ {
+ return 0;
+ }
+
+ // Get the params:
+ lua_pushstring(tolua_S, ".self");
+ lua_rawget(tolua_S, 1);
+ StatisticsManager * Self = static_cast<StatisticsManager *>(lua_touserdata(tolua_S, -1));
+ CustomStatistic Statistic;
+ StatisticsManager::StatValue Value;
+ if (!L.GetStackValues(2, Statistic, Value))
+ {
+ return L.ApiParamError("Expected a valid custom statistic ID and value");
+ }
+
+ // Set the value:
+ Self->Custom[Statistic] = Value;
+
+ return 0;
+}
+
+
+
+
+
void cManualBindings::Bind(lua_State * tolua_S)
{
tolua_beginmodule(tolua_S, nullptr);
@@ -4357,10 +4420,12 @@ void cManualBindings::Bind(lua_State * tolua_S)
tolua_usertype(tolua_S, "cLineBlockTracer");
tolua_usertype(tolua_S, "cStringCompression");
tolua_usertype(tolua_S, "cUrlParser");
+ // StatisticsManager was already created by cPlayer::GetStatistics' autogenerated bindings.
tolua_cclass(tolua_S, "cCryptoHash", "cCryptoHash", "", nullptr);
tolua_cclass(tolua_S, "cLineBlockTracer", "cLineBlockTracer", "", nullptr);
tolua_cclass(tolua_S, "cStringCompression", "cStringCompression", "", nullptr);
tolua_cclass(tolua_S, "cUrlParser", "cUrlParser", "", nullptr);
+ tolua_cclass(tolua_S, "StatisticsManager", "StatisticsManager", "", nullptr);
// Globals:
tolua_function(tolua_S, "Clamp", tolua_Clamp);
@@ -4592,6 +4657,10 @@ void cManualBindings::Bind(lua_State * tolua_S)
tolua_variable(tolua_S, "PostParams", tolua_get_HTTPRequest_PostParams, nullptr);
tolua_endmodule(tolua_S);
+ tolua_beginmodule(tolua_S, "StatisticsManager");
+ tolua_array(tolua_S, "Custom", tolua_get_StatisticsManager_Custom, tolua_set_StatisticsManager_Custom);
+ tolua_endmodule(tolua_S);
+
BindNetwork(tolua_S);
BindRankManager(tolua_S);
BindWorld(tolua_S);