Make lua binding for std::vector (#164)

* Make LuaImplQueryArg impl for std::vector

* Fix shadowed argument

* Make unit tests

* Bugfix

* Bugfix, for real this time

* We didn't need these tests anyway

* Revert "We didn't need these tests anyway"

This reverts commit be88d4496a9cf62beb4d3ce1f30825589a4bacb2.

* Add change to changelog

* Update ChangeLog.md

* Bugfix & use CallOnExit to pop stack
This commit is contained in:
S6066
2018-06-17 19:04:15 +02:00
committed by Jérôme Leclercq
parent 858d0da5f2
commit da044bd21c
3 changed files with 60 additions and 0 deletions

View File

@@ -3,6 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Flags.hpp>
#include <Nazara/Core/MemoryHelper.hpp>
#include <Nazara/Core/StringStream.hpp>
@@ -159,6 +160,34 @@ namespace Nz
return LuaImplQueryArg(instance, index, arg, defValue, TypeTag<T>());
}
template<typename T>
unsigned int LuaImplQueryArg(const LuaState& instance, int index, std::vector<T>* container, TypeTag<std::vector<T>>)
{
instance.CheckType(index, Nz::LuaType_Table);
std::size_t pos = 1;
for (;;)
{
Nz::CallOnExit popStack { [&instance]() { instance.Pop(); } };
instance.PushInteger(pos++);
if (instance.GetTable() == Nz::LuaType_Nil)
break;
T arg {};
if (LuaImplQueryArg(instance, -1, &arg, TypeTag<T>()) != 1)
{
instance.Error("Type needs more than one place to be initialized");
return 0;
}
container->push_back(arg);
}
return 1;
}
// Function returns
inline int LuaImplReplyVal(const LuaState& instance, bool val, TypeTag<bool>)
{