Lua/LuaInstance: Add automatic conversion of std::vector
Former-commit-id: 31b32f9c4b9ccd825f2d08ea8499211040a0b9ab
This commit is contained in:
parent
bf288e7f06
commit
9390ce35b3
|
|
@ -7,6 +7,7 @@
|
||||||
#include <Nazara/Core/StringStream.hpp>
|
#include <Nazara/Core/StringStream.hpp>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
|
|
@ -149,6 +150,25 @@ namespace Nz
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline int LuaImplReplyVal(const LuaInstance& instance, std::vector<T> valContainer, TypeTag<std::vector<T>>)
|
||||||
|
{
|
||||||
|
std::size_t index = 1;
|
||||||
|
instance.PushTable(valContainer.size());
|
||||||
|
for (const T& val : valContainer)
|
||||||
|
{
|
||||||
|
instance.PushInteger(index++);
|
||||||
|
if (LuaImplReplyVal(instance, val, TypeTag<T>()) != 1)
|
||||||
|
{
|
||||||
|
instance.Error("Couldn't create table: type need more than one place to store");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
instance.SetTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
inline int LuaImplReplyVal(const LuaInstance& instance, ByteArray val, TypeTag<ByteArray>)
|
inline int LuaImplReplyVal(const LuaInstance& instance, ByteArray val, TypeTag<ByteArray>)
|
||||||
{
|
{
|
||||||
instance.PushString(reinterpret_cast<const char*>(val.GetConstBuffer()), val.GetSize());
|
instance.PushString(reinterpret_cast<const char*>(val.GetConstBuffer()), val.GetSize());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue