diff --git a/sol/stack.hpp b/sol/stack.hpp index b6d14f3f..ff3ceeb9 100644 --- a/sol/stack.hpp +++ b/sol/stack.hpp @@ -167,11 +167,27 @@ auto pop(lua_State* L) -> decltype(get(L)) { return r; } -template -inline EnableIf> push(lua_State* L, T arithmetic) { +template::value> +inline typename std::enable_if::type push(lua_State* L, T arithmetic) { detail::push_arithmetic(std::is_integral{}, L, arithmetic); } +template::value && + !std::is_same, std::string>::value && + has_begin_end::value> +inline typename std::enable_if::type push(lua_State* L, const T& cont) { + lua_createtable(L, cont.size(), 0); + unsigned index = 1; + for(auto&& i : cont) { + // push the index + push(L, index++); + // push the value + push(L, i); + // set the table + lua_settable(L, -3); + } +} + inline void push(lua_State*, reference& ref) { ref.push(); } diff --git a/sol/traits.hpp b/sol/traits.hpp index d87d2805..5918d33a 100644 --- a/sol/traits.hpp +++ b/sol/traits.hpp @@ -157,6 +157,19 @@ struct function_traits { template using arg = typename std::tuple_element::type; }; + +struct has_begin_end_impl { + template, + typename B = decltype(std::declval().begin()), + typename E = decltype(std::declval().end())> + static std::true_type test(int); + + template + static std::false_type test(...); +}; + +template +struct has_begin_end : decltype(has_begin_end_impl::test(0)) {}; } // sol #endif // SOL_TRAITS_HPP