-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathData.cpp
41 lines (37 loc) · 1.45 KB
/
Data.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "Data.h"
namespace Data {
void LuaVariant::push(hks::lua_State* L) const {
std::visit([L](auto&& arg) {
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, std::string>) {
hks::pushfstring(L, arg.c_str());
}
else if constexpr (std::is_same_v<T, double>) {
hks::pushnumber(L, arg);
}
else if constexpr (std::is_same_v<T, int>) {
hks::pushinteger(L, arg);
}
}, *this);
}
void LuaVariantMap::rebuild(hks::lua_State* L) {
for (auto& variantPair : *this) {
hks::pushfstring(L, variantPair.first.c_str());
hks::gettable(L, -2);
std::visit([L, &variantPair](auto&& arg) {
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, std::string>) {
size_t length = 0;
variantPair.second = LuaVariant(std::string(hks::checklstring(L, -1, &length)));
}
else if constexpr (std::is_same_v<T, double>) {
variantPair.second = LuaVariant(hks::checknumber(L, -1));
}
else if constexpr (std::is_same_v<T, int>) {
variantPair.second = LuaVariant(hks::checkinteger(L, -1));
}
}, variantPair.second);
hks::pop(L, 1);
}
}
}