MCPcopy Create free account
hub / github.com/ThePhD/sol2 / lua_value

Class lua_value

include/sol/lua_value.hpp:32–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30
31namespace sol {
32 struct lua_value {
33 public:
34 struct arr : detail::ebco<std::initializer_list<lua_value>> {
35 private:
36 using base_t = detail::ebco<std::initializer_list<lua_value>>;
37
38 public:
39 using base_t::base_t;
40 };
41
42 private:
43 template <typename T>
44 using is_reference_or_lua_value_init_list
45 = meta::any<meta::is_specialization_of<T, std::initializer_list>, std::is_same<T, reference>, std::is_same<T, arr>>;
46
47 template <typename T>
48 using is_lua_value_single_constructible = meta::any<std::is_same<T, lua_value>, is_reference_or_lua_value_init_list<T>>;
49
50 static lua_State*& thread_local_lua_state() {
51#if SOL_IS_ON(SOL_USE_THREAD_LOCAL)
52 static thread_local lua_State* L = nullptr;
53#else
54 static lua_State* L = nullptr;
55#endif
56 return L;
57 }
58
59 reference ref_value;
60
61 public:
62 static void set_lua_state(lua_State* L) {
63 thread_local_lua_state() = L;
64 }
65
66 template <typename T, meta::disable<is_reference_or_lua_value_init_list<meta::unqualified_t<T>>> = meta::enabler>
67 lua_value(lua_State* L_, T&& value) : lua_value(((set_lua_state(L_)), std::forward<T>(value))) {
68 }
69
70 template <typename T, meta::disable<is_lua_value_single_constructible<meta::unqualified_t<T>>> = meta::enabler>
71 lua_value(T&& value) : ref_value(make_reference(thread_local_lua_state(), std::forward<T>(value))) {
72 }
73
74 lua_value(lua_State* L_, std::initializer_list<std::pair<lua_value, lua_value>> il)
75 : lua_value([&L_, &il]() {
76 set_lua_state(L_);
77 return std::move(il);
78 }()) {
79 }
80
81 lua_value(std::initializer_list<std::pair<lua_value, lua_value>> il) : ref_value(make_reference(thread_local_lua_state(), std::move(il))) {
82 }
83
84 lua_value(lua_State* L_, arr il)
85 : lua_value([&L_, &il]() {
86 set_lua_state(L_);
87 return std::move(il);
88 }()) {
89 }

Callers 1

getMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected