#ifndef SOL_CONTAINER_HPP #define SOL_CONTAINER_HPP #include "userdata.hpp" namespace sol { template struct container { typedef typename std::conditional::value, Tc, Decay>::type T; typedef Decay().begin()))> value_type; T cont; template container (Args&&... args) : cont(std::forward(args)...){ } operator T& () const { return cont; } void set( std::ptrdiff_t i, const value_type& value ) { cont[ i ] = value; } value_type& get( std::ptrdiff_t i ) { return cont[ i ]; } std::size_t size( ) const { return cont.size(); } }; namespace stack { template struct pusher::value>::type> { template static void push(lua_State *L, U&& t){ typedef container container_t; // todo: NEED to find a different way of handling this... static std::vector> classes{}; userdata classdata(default_constructor, "__index", &container_t::get, "__newindex", &container_t::set, "__len", &container_t::size); classes.emplace_back(std::make_shared>(std::move(classdata))); auto&& ptr = classes.back(); auto udata = std::static_pointer_cast>(ptr); stack::push(L, *udata); container_t* c = static_cast(lua_newuserdata(L, sizeof(container_t))); std::allocator alloc{}; alloc.construct(c, std::forward(t)); auto&& meta = userdata_traits::metatable; luaL_getmetatable(L, std::addressof(meta[0])); lua_setmetatable(L, -2); } template>> = 0> static void push(lua_State* L, const T& cont) { lua_createtable(L, cont.size(), 0); unsigned index = 1; for(auto&& i : cont) { // push the index pusher::push(L, index++); // push the value pusher>::push(L, i); // set the table lua_settable(L, -3); } } template> = 0> static void push(lua_State* L, const T& cont) { lua_createtable(L, cont.size(), 0); for(auto&& pair : cont) { pusher>::push(L, pair.first); pusher>::push(L, pair.second); lua_settable(L, -3); } } }; } // stack } // sol #endif // SOL_CONTAINER_HPP