• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kunitoki / LuaBridge3 / 25548440551

08 May 2026 09:36AM UTC coverage: 95.876% (-0.03%) from 95.901%
25548440551

push

github

web-flow
Add support for modern C++ features (#236)

320 of 332 new or added lines in 15 files covered. (96.39%)

3 existing lines in 1 file now uncovered.

4789 of 4995 relevant lines covered (95.88%)

49770.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.88
/Source/LuaBridge/UnorderedMultiMap.h
1
// https://github.com/kunitoki/LuaBridge3
2
// Copyright 2026, kunitoki
3
// SPDX-License-Identifier: MIT
4

5
#pragma once
6

7
#include "detail/Stack.h"
8

9
#include <unordered_map>
10

11
namespace luabridge {
12

13
//=================================================================================================
14
/**
15
 * @brief Stack specialization for `std::unordered_multimap`.
16
 */
17
template <class K, class V, class Hash, class KeyEqual, class Allocator>
18
struct Stack<std::unordered_multimap<K, V, Hash, KeyEqual, Allocator>>
19
{
20
    using Type = std::unordered_multimap<K, V, Hash, KeyEqual, Allocator>;
21

22
    [[nodiscard]] static Result push(lua_State* L, const Type& map)
360✔
23
    {
24
#if LUABRIDGE_SAFE_STACK_CHECKS
25
        if (! lua_checkstack(L, 3))
360✔
26
            return makeErrorCode(ErrorCode::LuaStackOverflow);
72✔
27
#endif
28

29
        StackRestore stackRestore(L);
288✔
30

31
        lua_createtable(L, 0, 0);
288✔
32

33
        auto it = map.begin();
288✔
34
        while (it != map.end())
648✔
35
        {
36
            auto result = Stack<K>::push(L, it->first);
360✔
37
            if (! result)
360✔
NEW
38
                return result;
×
39

40
            auto range = map.equal_range(it->first);
360✔
41
            lua_createtable(L, static_cast<int>(std::distance(range.first, range.second)), 0);
360✔
42

43
            int innerIndex = 1;
360✔
44
            for (auto innerIt = range.first; innerIt != range.second; ++innerIt, ++innerIndex)
1,008✔
45
            {
46
                result = Stack<V>::push(L, innerIt->second);
648✔
47
                if (! result)
648✔
NEW
48
                    return result;
×
49

50
                lua_rawseti(L, -2, innerIndex);
648✔
51
            }
52

53
            lua_settable(L, -3);
360✔
54
            it = range.second;
360✔
55
        }
56

57
        stackRestore.reset();
288✔
58
        return {};
288✔
59
    }
288✔
60

61
    [[nodiscard]] static TypeResult<Type> get(lua_State* L, int index)
432✔
62
    {
63
        if (! lua_istable(L, index))
432✔
64
            return makeErrorCode(ErrorCode::InvalidTypeCast);
72✔
65

66
        const StackRestore stackRestore(L);
360✔
67

68
        Type map;
360✔
69

70
        int absIndex = lua_absindex(L, index);
360✔
71
        lua_pushnil(L);
360✔
72

73
        while (lua_next(L, absIndex) != 0)
936✔
74
        {
75
            auto key = Stack<K>::get(L, -2);
360✔
76
            if (! key)
360✔
NEW
77
                return makeErrorCode(ErrorCode::InvalidTypeCast);
×
78

79
            if (! lua_istable(L, -1))
360✔
80
                return makeErrorCode(ErrorCode::InvalidTypeCast);
72✔
81

82
            int innerAbsIndex = lua_absindex(L, -1);
288✔
83
            lua_pushnil(L);
288✔
84

85
            while (lua_next(L, innerAbsIndex) != 0)
1,224✔
86
            {
87
                auto value = Stack<V>::get(L, -1);
504✔
88
                if (! value)
504✔
89
                    return makeErrorCode(ErrorCode::InvalidTypeCast);
72✔
90

91
                map.emplace(*key, *value);
432✔
92
                lua_pop(L, 1);
432✔
93
            }
94

95
            lua_pop(L, 1);
216✔
96
        }
97

98
        return map;
216✔
99
    }
360✔
100

101
    [[nodiscard]] static bool isInstance(lua_State* L, int index)
144✔
102
    {
103
        return lua_istable(L, index);
144✔
104
    }
105
};
106

107
} // namespace luabridge
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc