forked from diasurgical/DevilutionX
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmetadoc.hpp
More file actions
53 lines (41 loc) · 1.42 KB
/
metadoc.hpp
File metadata and controls
53 lines (41 loc) · 1.42 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once
#include <sol/sol.hpp>
#include <string_view>
#include "utils/str_cat.hpp"
namespace devilution {
inline std::string LuaSignatureKey(std::string_view key)
{
return StrCat("__sig_", key);
}
inline std::string LuaDocstringKey(std::string_view key)
{
return StrCat("__doc_", key);
}
template <typename U, typename T>
void SetDocumented(sol::usertype<U> &table, std::string_view key, std::string_view signature, std::string_view doc, T &&value)
{
table[key] = std::forward<T>(value);
// TODO: figure out a way to set signature and docstring.
}
template <typename T>
void SetDocumented(sol::table &table, std::string_view key, std::string_view signature, std::string_view doc, T &&value)
{
table[key] = std::forward<T>(value);
table[LuaSignatureKey(key)] = signature;
table[LuaDocstringKey(key)] = doc;
}
template <typename T>
void SetWithSignature(sol::table &table, std::string_view key, std::string_view signature, T &&value)
{
table[key] = std::forward<T>(value);
table[LuaSignatureKey(key)] = signature;
}
inline std::optional<std::string> GetSignature(const sol::table &table, std::string_view key)
{
return table.get<std::optional<std::string>>(LuaSignatureKey(key));
}
inline std::optional<std::string> GetDocstring(const sol::table &table, std::string_view key)
{
return table.get<std::optional<std::string>>(LuaDocstringKey(key));
}
} // namespace devilution