summaryrefslogtreecommitdiffstats
path: root/src/Bindings/ManualBindings.cpp
diff options
context:
space:
mode:
authorLukas Pioch <lukas@zgow.de>2017-07-31 11:54:31 +0200
committerLukas Pioch <lukas@zgow.de>2017-08-27 14:54:41 +0200
commit92133f7de4bf75c203bace5d5269360eb6ab78f9 (patch)
tree191caf222ba5731bfe506a7601939fdd39938085 /src/Bindings/ManualBindings.cpp
parentAdded check if the player is holding a book and use SendEquippedSlot to send the item change (diff)
downloadcuberite-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 'src/Bindings/ManualBindings.cpp')
-rw-r--r--src/Bindings/ManualBindings.cpp34
1 files changed, 15 insertions, 19 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;
}