Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Pusher and Reader for unordered_map with Hash param #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions include/LuaContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1971,12 +1971,12 @@ struct LuaContext::Pusher<std::map<TKey,TValue>> {
};

// unordered_maps
template<typename TKey, typename TValue>
struct LuaContext::Pusher<std::unordered_map<TKey,TValue>> {
template<typename TKey, typename TValue, typename THasher>
struct LuaContext::Pusher<std::unordered_map<TKey,TValue,THasher>> {
static const int minSize = 1;
static const int maxSize = 1;

static PushedObject push(lua_State* state, const std::unordered_map<TKey,TValue>& value) noexcept {
static PushedObject push(lua_State* state, const std::unordered_map<TKey,TValue,THasher>& value) noexcept {
static_assert(Pusher<typename std::decay<TKey>::type>::minSize == 1 && Pusher<typename std::decay<TKey>::type>::maxSize == 1, "Can't push multiple elements for a table key");
static_assert(Pusher<typename std::decay<TValue>::type>::minSize == 1 && Pusher<typename std::decay<TValue>::type>::maxSize == 1, "Can't push multiple elements for a table value");

Expand Down Expand Up @@ -2616,16 +2616,16 @@ struct LuaContext::Reader<std::map<TKey,TValue>>
};

// unordered_map
template<typename TKey, typename TValue>
struct LuaContext::Reader<std::unordered_map<TKey,TValue>>
template<typename TKey, typename TValue, typename THasher>
struct LuaContext::Reader<std::unordered_map<TKey,TValue,THasher>>
{
static auto read(lua_State* state, int index)
-> boost::optional<std::unordered_map<TKey,TValue>>
-> boost::optional<std::unordered_map<TKey,TValue,THasher>>
{
if (!lua_istable(state, index))
return boost::none;

std::unordered_map<TKey,TValue> result;
std::unordered_map<TKey,TValue,THasher> result;

// we traverse the table at the top of the stack
lua_pushnil(state); // first key
Expand Down