#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 Unqualified().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(); } }; template struct container>::value>::type> { typedef typename std::conditional::value, Tc, Decay>::type T; typedef Unqualified().begin())).first)> key_type; typedef Unqualified().begin())).second)> value_type; T cont; template container (Args&&... args) : cont(std::forward(args)...){ } operator T& () const { return cont; } void set(key_type i, const value_type& value) { cont[ i ] = value; } value_type& get(key_type i) { return cont.at(i); } std::size_t size() const { return cont.size(); } }; namespace stack { template struct pusher::value>::type> { static void push(lua_State* L, const T& cont) { 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, cont); auto&& meta = userdata_traits::metatable; if (luaL_newmetatable(L, std::addressof(meta[0])) == 1) { std::string err("metatable not defined for "); err += meta; throw error(err); } lua_setmetatable(L, -2); } }; template struct getter::value>::type> { static Unqualified& get(lua_State* L, int index = -1) { typedef container> container_t; container_t& data = stack::get(L, index); return data.cont; } }; } // stack } // sol #endif // SOL_CONTAINER_HPP