@@ -35,6 +35,20 @@ enum LuaTypeTag
35
35
TBOOL,
36
36
};
37
37
38
+ class LuaVal ;
39
+ size_t LuaValHash (LuaVal const & v);
40
+
41
+ namespace std {
42
+ template <>
43
+ struct hash <LuaVal> {
44
+ public:
45
+ size_t operator ()(LuaVal const & v) const
46
+ {
47
+ return LuaValHash (v);
48
+ };
49
+ };
50
+ }
51
+
38
52
class LuaVal
39
53
{
40
54
public:
@@ -52,7 +66,7 @@ class LuaVal
52
66
size_t operator ()(LuaVal const & v) const ;
53
67
};
54
68
55
- typedef std::unordered_map<LuaVal, LuaVal, LuaValHasher > LuaTable;
69
+ typedef std::unordered_map<LuaVal, LuaVal> LuaTable;
56
70
typedef std::unique_ptr<LuaTable> TblPtr; // circular reference memleak if insert self to self
57
71
58
72
LuaVal (const LuaTypeTag tag) : tag(tag), tbl_ptr(tag == TTABLE ? new LuaTable() : nullptr ), d(0 ), b(false ) {}
@@ -63,7 +77,6 @@ class LuaVal
63
77
LuaVal (const std::string & s) : tag(TSTRING), tbl_ptr(nullptr ), s(s), d(0 ), b(false ) {}
64
78
LuaVal (const char * s) : tag(TSTRING), tbl_ptr(nullptr ), s(s), d(0 ), b(false ) {}
65
79
LuaVal (const bool b) : tag(TBOOL), tbl_ptr(nullptr ), d(0 ), b(b) {}
66
- LuaVal (LuaTable const & luatable) : tag(TTABLE), tbl_ptr(new LuaTable(luatable)), d(0 ), b(false ) {}
67
80
LuaVal (LuaVal const & val) : tag(val.tag), tbl_ptr(val.tag == TTABLE ? val.tbl_ptr ? new LuaTable(*val.tbl_ptr) : new LuaTable() : nullptr ), s(val.s), d(val.d), b(val.b) {}
68
81
LuaVal (LuaVal && val) noexcept : tag(std::move(val.tag)), tbl_ptr(std::move(val.tbl_ptr)), s(std::move(val.s)), d(std::move(val.d)), b(std::move(val.b)) {}
69
82
LuaVal (std::initializer_list<LuaVal> const & l) : tag(TTABLE), tbl_ptr(new LuaTable()), d(0 ), b(false )
@@ -122,9 +135,8 @@ class LuaVal
122
135
{
123
136
InitializeMap (l);
124
137
}
125
- LuaVal (std::unordered_map<LuaVal, LuaVal> const & l) : tag(TTABLE), tbl_ptr(new LuaTable()), d(0 ), b(false )
138
+ LuaVal (std::unordered_map<LuaVal, LuaVal> const & l) : tag(TTABLE), tbl_ptr(new LuaTable(l )), d(0 ), b(false )
126
139
{
127
- InitializeMap (l);
128
140
}
129
141
template <typename K, typename V> LuaVal (std::unordered_map<K, V> const & l) : tag(TTABLE), tbl_ptr(new LuaTable()), d(0 ), b(false )
130
142
{
@@ -271,6 +283,8 @@ class LuaVal
271
283
tbl[std::move (k)] = std::move (v);
272
284
}
273
285
}
286
+
287
+ friend size_t LuaValHash (LuaVal const & v);
274
288
275
289
LuaTypeTag tag;
276
290
TblPtr tbl_ptr;
0 commit comments