From 9390ce35b3073b6441b9df4f2ca2cb70666ed98a Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 30 Mar 2016 18:06:18 +0200 Subject: [PATCH] Lua/LuaInstance: Add automatic conversion of std::vector Former-commit-id: 31b32f9c4b9ccd825f2d08ea8499211040a0b9ab --- include/Nazara/Lua/LuaInstance.inl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/Nazara/Lua/LuaInstance.inl b/include/Nazara/Lua/LuaInstance.inl index 32103afe3..685c50719 100644 --- a/include/Nazara/Lua/LuaInstance.inl +++ b/include/Nazara/Lua/LuaInstance.inl @@ -7,6 +7,7 @@ #include #include #include +#include #include namespace Nz @@ -149,6 +150,25 @@ namespace Nz return 1; } + template + inline int LuaImplReplyVal(const LuaInstance& instance, std::vector valContainer, TypeTag>) + { + std::size_t index = 1; + instance.PushTable(valContainer.size()); + for (const T& val : valContainer) + { + instance.PushInteger(index++); + if (LuaImplReplyVal(instance, val, TypeTag()) != 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) { instance.PushString(reinterpret_cast(val.GetConstBuffer()), val.GetSize());