summaryrefslogtreecommitdiffstats
path: root/src/Bindings
diff options
context:
space:
mode:
Diffstat (limited to 'src/Bindings')
-rw-r--r--src/Bindings/DeprecatedBindings.cpp56
-rw-r--r--src/Bindings/LuaState.cpp31
-rw-r--r--src/Bindings/LuaState.h1
-rw-r--r--src/Bindings/ManualBindings.cpp76
4 files changed, 154 insertions, 10 deletions
diff --git a/src/Bindings/DeprecatedBindings.cpp b/src/Bindings/DeprecatedBindings.cpp
index e75250604..3ae1fd990 100644
--- a/src/Bindings/DeprecatedBindings.cpp
+++ b/src/Bindings/DeprecatedBindings.cpp
@@ -347,6 +347,58 @@ static int tolua_set_cBlockInfo_m_PlaceSound(lua_State * tolua_S)
+static int tolua_get_cItem_m_Lore(lua_State * tolua_S)
+{
+ // Maintain legacy m_Lore variable as Lore table split by ` (grave-accent)
+ cLuaState L(tolua_S);
+ if (!L.CheckParamSelf("const cItem"))
+ {
+ return 0;
+ }
+
+ const cItem * Self = nullptr;
+ L.GetStackValue(1, Self);
+
+ AString LoreString = StringJoin(Self->m_LoreTable, "`");
+
+ L.Push(LoreString);
+
+ LOGWARNING("cItem.m_Lore is deprecated, use cItem.m_LoreTable instead");
+ L.LogStackTrace(0);
+ return 1;
+}
+
+
+
+
+
+static int tolua_set_cItem_m_Lore(lua_State * tolua_S)
+{
+ // Maintain legacy m_Lore variable as Lore table split by ` (grave-accent)
+ cLuaState L(tolua_S);
+ if (
+ !L.CheckParamSelf("cItem") ||
+ !L.CheckParamString(2)
+ )
+ {
+ return 0;
+ }
+
+ cItem * Self = nullptr;
+ AString LoreString;
+ L.GetStackValues(1, Self, LoreString);
+
+ Self->m_LoreTable = StringSplit(LoreString, "`");
+
+ LOGWARNING("cItem.m_Lore is deprecated, use cItem.m_LoreTable instead");
+ L.LogStackTrace(0);
+ return 0;
+}
+
+
+
+
+
/* method: Trace of class cTracer */
static int tolua_cTracer_Trace(lua_State * a_LuaState)
{
@@ -500,6 +552,10 @@ void DeprecatedBindings::Bind(lua_State * tolua_S)
tolua_variable(tolua_S, "m_PlaceSound", tolua_get_cBlockInfo_m_PlaceSound, tolua_set_cBlockInfo_m_PlaceSound);
tolua_endmodule(tolua_S);
+ tolua_beginmodule(tolua_S, "cItem");
+ tolua_variable(tolua_S, "m_Lore", tolua_get_cItem_m_Lore, tolua_set_cItem_m_Lore);
+ tolua_endmodule(tolua_S);
+
tolua_beginmodule(tolua_S, "cTracer");
tolua_function(tolua_S, "Trace", tolua_cTracer_Trace);
tolua_endmodule(tolua_S);
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp
index 07a91f49e..185759acc 100644
--- a/src/Bindings/LuaState.cpp
+++ b/src/Bindings/LuaState.cpp
@@ -1151,6 +1151,37 @@ bool cLuaState::GetStackValue(int a_StackPos, AStringMap & a_Value)
+bool cLuaState::GetStackValue(int a_StackPos, AStringVector & a_Value)
+{
+ // Retrieve all values in an array of string table:
+ if (!lua_istable(m_LuaState, a_StackPos))
+ {
+ return false;
+ }
+ cStackTable tbl(*this, a_StackPos);
+ bool isValid = true;
+ tbl.ForEachArrayElement([&](cLuaState & a_LuaState, int a_Index)
+ {
+ AString tempStr;
+ if (a_LuaState.GetStackValue(-1, tempStr))
+ {
+ a_Value.push_back(std::move(tempStr));
+ }
+ else
+ {
+ isValid = false;
+ return true;
+ }
+ return false;
+ }
+ );
+ return isValid;
+}
+
+
+
+
+
bool cLuaState::GetStackValue(int a_StackPos, bool & a_ReturnedVal)
{
a_ReturnedVal = (tolua_toboolean(m_LuaState, a_StackPos, a_ReturnedVal ? 1 : 0) > 0);
diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h
index 1d2598813..ffcddcfe8 100644
--- a/src/Bindings/LuaState.h
+++ b/src/Bindings/LuaState.h
@@ -640,6 +640,7 @@ public:
// Enum values are checked for their allowed values and fail if the value is not assigned.
bool GetStackValue(int a_StackPos, AString & a_Value);
bool GetStackValue(int a_StackPos, AStringMap & a_Value);
+ bool GetStackValue(int a_StackPos, AStringVector & a_Value);
bool GetStackValue(int a_StackPos, bool & a_Value);
bool GetStackValue(int a_StackPos, cCallback & a_Callback);
bool GetStackValue(int a_StackPos, cCallbackPtr & a_Callback);
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 2251c64b9..6fe133e1e 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -11,11 +11,6 @@
#include "PluginLua.h"
#include "PluginManager.h"
#include "LuaWindow.h"
-#include "../Root.h"
-#include "../World.h"
-#include "../Entities/Player.h"
-#include "../WebAdmin.h"
-#include "../ClientHandle.h"
#include "../BlockArea.h"
#include "../BlockEntities/BeaconEntity.h"
#include "../BlockEntities/BrewingstandEntity.h"
@@ -28,14 +23,20 @@
#include "../BlockEntities/NoteEntity.h"
#include "../BlockEntities/MobHeadEntity.h"
#include "../BlockEntities/FlowerPotEntity.h"
+#include "../BoundingBox.h"
+#include "../BuildInfo.h"
+#include "../ClientHandle.h"
+#include "../CommandOutput.h"
+#include "../CompositeChat.h"
+#include "../Entities/Player.h"
#include "../Generating/ChunkDesc.h"
+#include "../HTTP/UrlParser.h"
+#include "../Item.h"
#include "../LineBlockTracer.h"
-#include "../CompositeChat.h"
+#include "../Root.h"
#include "../StringCompression.h"
-#include "../CommandOutput.h"
-#include "../BuildInfo.h"
-#include "../HTTP/UrlParser.h"
-#include "../BoundingBox.h"
+#include "../WebAdmin.h"
+#include "../World.h"
@@ -2557,6 +2558,57 @@ static int tolua_cMojangAPI_MakeUUIDShort(lua_State * L)
+static int tolua_get_cItem_m_LoreTable(lua_State * tolua_S)
+{
+ // Check params:
+ cLuaState L(tolua_S);
+ if (!L.CheckParamSelf("const cItem"))
+ {
+ return 0;
+ }
+
+ // Get the params:
+ const cItem * Self = nullptr;
+ L.GetStackValue(1, Self);
+
+ // Push the result:
+ L.Push(Self->m_LoreTable);
+ return 1;
+}
+
+
+
+
+
+static int tolua_set_cItem_m_LoreTable(lua_State * tolua_S)
+{
+ // Check params:
+ cLuaState L(tolua_S);
+ if (
+ !L.CheckParamSelf("cItem") ||
+ !L.CheckParamTable(2)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ cItem * Self = nullptr;
+ L.GetStackValue(1, Self);
+
+ // Set the value:
+ Self->m_LoreTable.clear();
+ if (!L.GetStackValue(2, Self->m_LoreTable))
+ {
+ return L.ApiParamError("cItem.m_LoreTable: Could not read value as an array of strings");
+ }
+ return 0;
+}
+
+
+
+
+
static int Lua_ItemGrid_GetSlotCoords(lua_State * L)
{
tolua_Error tolua_err;
@@ -3798,6 +3850,10 @@ void cManualBindings::Bind(lua_State * tolua_S)
tolua_function(tolua_S, "GetOutputBlockPos", tolua_cHopperEntity_GetOutputBlockPos);
tolua_endmodule(tolua_S);
+ tolua_beginmodule(tolua_S, "cItem");
+ tolua_variable(tolua_S, "m_LoreTable", tolua_get_cItem_m_LoreTable, tolua_set_cItem_m_LoreTable);
+ tolua_endmodule(tolua_S);
+
tolua_beginmodule(tolua_S, "cItemGrid");
tolua_function(tolua_S, "GetSlotCoords", Lua_ItemGrid_GetSlotCoords);
tolua_endmodule(tolua_S);