diff options
author | Lukas Pioch <lukas@zgow.de> | 2017-07-31 11:54:31 +0200 |
---|---|---|
committer | Lukas Pioch <lukas@zgow.de> | 2017-08-27 14:54:41 +0200 |
commit | 92133f7de4bf75c203bace5d5269360eb6ab78f9 (patch) | |
tree | 191caf222ba5731bfe506a7601939fdd39938085 /src | |
parent | Added check if the player is holding a book and use SendEquippedSlot to send the item change (diff) | |
download | cuberite-92133f7de4bf75c203bace5d5269360eb6ab78f9.tar cuberite-92133f7de4bf75c203bace5d5269360eb6ab78f9.tar.gz cuberite-92133f7de4bf75c203bace5d5269360eb6ab78f9.tar.bz2 cuberite-92133f7de4bf75c203bace5d5269360eb6ab78f9.tar.lz cuberite-92133f7de4bf75c203bace5d5269360eb6ab78f9.tar.xz cuberite-92133f7de4bf75c203bace5d5269360eb6ab78f9.tar.zst cuberite-92133f7de4bf75c203bace5d5269360eb6ab78f9.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Bindings/ManualBindings.cpp | 34 | ||||
-rw-r--r-- | src/BookContent.h | 3 |
2 files changed, 15 insertions, 22 deletions
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index b6ef2b275..45fc11ccb 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -3972,11 +3972,13 @@ static int tolua_cBookContent_GetPages(lua_State * tolua_S) // cBookContent::GetPages() -> table of strings cLuaState L(tolua_S); - if (!L.CheckParamSelf("cBookContent")) + if ( + !L.CheckParamSelf("cBookContent") || + !L.CheckParamEnd(2) + ) { return 0; } - cBookContent * BookContent = reinterpret_cast<cBookContent *>(tolua_tousertype(tolua_S, 1, nullptr)); L.Push(BookContent->GetPages()); return 1; @@ -3993,29 +3995,23 @@ static int tolua_cBookContent_SetPages(lua_State * tolua_S) cLuaState L(tolua_S); if ( !L.CheckParamSelf("cBookContent") || - !L.CheckParamTable(2)) + !L.CheckParamTable(2) || + !L.CheckParamEnd(3) + ) { return 0; } - cBookContent * BookContent = reinterpret_cast<cBookContent *>(tolua_tousertype(tolua_S, 1, nullptr)); - - // Convert the input table into AStringVector: - AStringVector Pages; - int NumPages = luaL_getn(L, 2); - Pages.reserve(static_cast<size_t>(NumPages)); - for (int i = 1; i <= NumPages; i++) - { - lua_rawgeti(L, 2, i); - AString Page; - L.GetStackValue(-1, Page); - if (!Page.empty()) + cLuaState::cStackTablePtr Pages; + L.GetStackValue(2, Pages); + Pages->ForEachArrayElement([=](cLuaState & a_LuaState, int a_Index) -> bool { - Pages.push_back(Page); + AString Page; + a_LuaState.GetStackValue(-1, Page); + BookContent->AddPage(Page); + return false; } - lua_pop(L, 1); - } - BookContent->SetPages(Pages); + ); return 0; } diff --git a/src/BookContent.h b/src/BookContent.h index 51e261ecc..001da824c 100644 --- a/src/BookContent.h +++ b/src/BookContent.h @@ -42,9 +42,6 @@ public: /** Returns a AStringVector ref to the pages. Used in ManualBindings and for saving the book */ const AStringVector & GetPages(void) const { return m_Pages; } - /** Set the pages. Used in ManualBindings */ - void SetPages(const AStringVector & a_Pages) { m_Pages = a_Pages; } - /** Read the book content from nbt. The boolean a_SaveAsJson is optional. If a player creates a book, the text should be in a json string */ static void ParseFromNBT(int TagTag, cBookContent & a_BookContent, const cParsedNBT & a_NBT, bool a_SaveAsJson = false); |