Skip to content

Commit ee13a78

Browse files
committed
Full fixes for everything.
1 parent b6f4093 commit ee13a78

20 files changed

Lines changed: 1896 additions & 2283 deletions

examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ function (MAKE_EXAMPLE example_source_file example_suffix target_sol)
8585
else()
8686
target_compile_options(${example_name}
8787
PRIVATE -std=c++1z
88+
-ftemplate-backtrace-limit=0
8889
-Wall -Wpedantic -Werror -pedantic -pedantic-errors
8990
-Wno-noexcept-type
9091
-Wno-unknown-warning -Wno-unknown-warning-option)

examples/source/any_return.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,6 @@ int main() {
4444
std::cout << "result2: " << result2 << std::endl;
4545
std::cout << "result3: " << result3 << std::endl;
4646
std::cout << std::endl;
47+
48+
return 0;
4749
}

examples/source/customization_multiple.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ struct two_things {
1010
};
1111

1212
template <typename Handler>
13-
bool check(sol::types<two_things>, lua_State* L, int index, Handler&& handler, sol::stack::record& tracking) {
13+
bool sol_lua_check(sol::types<two_things>, lua_State* L, int index, Handler&& handler, sol::stack::record& tracking) {
1414
// indices can be negative to count backwards from the top of the stack,
1515
// rather than the bottom up
1616
// to deal with this, we adjust the index to
@@ -22,7 +22,7 @@ bool check(sol::types<two_things>, lua_State* L, int index, Handler&& handler, s
2222
return success;
2323
}
2424

25-
two_things get(sol::types<two_things>, lua_State* L, int index, sol::stack::record& tracking) {
25+
two_things sol_lua_get(sol::types<two_things>, lua_State* L, int index, sol::stack::record& tracking) {
2626
int absolute_index = lua_absindex(L, index);
2727
// Get the first element
2828
int a = sol::stack::get<int>(L, absolute_index);
@@ -34,7 +34,7 @@ two_things get(sol::types<two_things>, lua_State* L, int index, sol::stack::reco
3434
return two_things{ a, b };
3535
}
3636

37-
int push(sol::types<two_things>, lua_State* L, const two_things& things) {
37+
int sol_lua_push(sol::types<two_things>, lua_State* L, const two_things& things) {
3838
int amount = sol::stack::push(L, things.a);
3939
// amount will be 1: int pushes 1 item
4040
amount += sol::stack::push(L, things.b);

include/sol/forward.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
#include <utility>
3030
#include <type_traits>
3131

32+
#if defined(SOL_USING_CXX_LUA) && SOL_USING_CXX_LUA
33+
struct lua_State;
34+
#else
35+
extern "C" {
36+
struct lua_State;
37+
}
38+
#endif // C++ Mangling for Lua vs. Not
39+
3240
namespace sol {
3341

3442
template <bool b>

include/sol/proxy.hpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ namespace sol {
4646
}
4747

4848
auto setup_table(std::true_type) {
49-
auto p = stack::probe_get_field<std::is_same<meta::unqualified_t<Table>, global_table>::value>(lua_state(), key, tbl.stack_index());
49+
auto p = stack::probe_get_field<std::is_same_v<meta::unqualified_t<Table>, global_table>>(lua_state(), key, tbl.stack_index());
5050
lua_pop(lua_state(), p.levels);
5151
return p;
5252
}
5353

5454
bool is_valid(std::false_type) {
5555
auto pp = stack::push_pop(tbl);
56-
auto p = stack::probe_get_field<std::is_same<meta::unqualified_t<Table>, global_table>::value>(lua_state(), key, lua_gettop(lua_state()));
56+
auto p = stack::probe_get_field<std::is_same_v<meta::unqualified_t<Table>, global_table>>(lua_state(), key, lua_gettop(lua_state()));
5757
lua_pop(lua_state(), p.levels);
5858
return p;
5959
}
@@ -69,7 +69,7 @@ namespace sol {
6969

7070
template <typename T>
7171
proxy& set(T&& item) {
72-
tuple_set(std::make_index_sequence<std::tuple_size<meta::unqualified_t<key_type>>::value>(), std::forward<T>(item));
72+
tuple_set(std::make_index_sequence<std::tuple_size_v<meta::unqualified_t<key_type>>>(), std::forward<T>(item));
7373
return *this;
7474
}
7575

@@ -79,14 +79,15 @@ namespace sol {
7979
return *this;
8080
}
8181

82-
template <typename U, meta::enable<meta::neg<is_lua_reference_or_proxy<meta::unwrap_unqualified_t<U>>>, meta::is_callable<meta::unwrap_unqualified_t<U>>> = meta::enabler>
83-
proxy& operator=(U&& other) {
84-
return set_function(std::forward<U>(other));
85-
}
86-
87-
template <typename U, meta::disable<meta::neg<is_lua_reference_or_proxy<meta::unwrap_unqualified_t<U>>>, meta::is_callable<meta::unwrap_unqualified_t<U>>> = meta::enabler>
82+
template <typename U>
8883
proxy& operator=(U&& other) {
89-
return set(std::forward<U>(other));
84+
using uTu = meta::unwrap_unqualified_t<U>;
85+
if constexpr (!is_lua_reference_or_proxy_v<uTu> && meta::is_callable_v<uTu>) {
86+
return set_function(std::forward<U>(other));
87+
}
88+
else {
89+
return set(std::forward<U>(other));
90+
}
9091
}
9192

9293
template <typename T>
@@ -193,26 +194,26 @@ namespace sol {
193194

194195
template <typename Table, typename Key, typename T>
195196
inline bool operator==(T&& left, const proxy<Table, Key>& right) {
196-
typedef decltype(stack::get<T>(nullptr, 0)) U;
197-
return right.template get<optional<U>>() == left;
197+
using G = decltype(stack::get<T>(nullptr, 0));
198+
return right.template get<optional<G>>() == left;
198199
}
199200

200201
template <typename Table, typename Key, typename T>
201202
inline bool operator==(const proxy<Table, Key>& right, T&& left) {
202-
typedef decltype(stack::get<T>(nullptr, 0)) U;
203-
return right.template get<optional<U>>() == left;
203+
using G = decltype(stack::get<T>(nullptr, 0));
204+
return right.template get<optional<G>>() == left;
204205
}
205206

206207
template <typename Table, typename Key, typename T>
207208
inline bool operator!=(T&& left, const proxy<Table, Key>& right) {
208-
typedef decltype(stack::get<T>(nullptr, 0)) U;
209-
return right.template get<optional<U>>() != left;
209+
using G = decltype(stack::get<T>(nullptr, 0));
210+
return right.template get<optional<G>>() != left;
210211
}
211212

212213
template <typename Table, typename Key, typename T>
213214
inline bool operator!=(const proxy<Table, Key>& right, T&& left) {
214-
typedef decltype(stack::get<T>(nullptr, 0)) U;
215-
return right.template get<optional<U>>() != left;
215+
using G = decltype(stack::get<T>(nullptr, 0));
216+
return right.template get<optional<G>>() != left;
216217
}
217218

218219
template <typename Table, typename Key>

include/sol/stack_check_get_qualified.hpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,25 @@ namespace sol { namespace stack {
3535

3636
template <typename Handler>
3737
static optional<R> get(lua_State* L, int index, Handler&& handler, record& tracking) {
38-
if (!check<T>(L, index, std::forward<Handler>(handler))) {
39-
tracking.use(static_cast<int>(!lua_isnone(L, index)));
40-
return nullopt;
38+
if constexpr (is_lua_reference_v<T>) {
39+
// actually check if it's none here, otherwise
40+
// we'll have a none object inside an optional!
41+
bool success = lua_isnoneornil(L, index) == 0 && stack::check<T>(L, index, no_panic);
42+
if (!success) {
43+
// expected type, actual type
44+
tracking.use(static_cast<int>(success));
45+
handler(L, index, type::poly, type_of(L, index), "");
46+
return nullopt;
47+
}
48+
return stack_detail::unchecked_get<T>(L, index, tracking);
4149
}
42-
return stack_detail::unchecked_get<T>(L, index, tracking);
43-
}
44-
};
45-
46-
template <typename T>
47-
struct qualified_check_getter<T, std::enable_if_t<is_lua_reference<T>::value>> {
48-
template <typename Handler>
49-
static optional<T> get(lua_State* L, int index, Handler&& handler, record& tracking) {
50-
// actually check if it's none here, otherwise
51-
// we'll have a none object inside an optional!
52-
bool success = lua_isnoneornil(L, index) == 0 && stack::check<T>(L, index, no_panic);
53-
if (!success) {
54-
// expected type, actual type
55-
tracking.use(static_cast<int>(success));
56-
handler(L, index, type::poly, type_of(L, index), "");
57-
return nullopt;
50+
else {
51+
if (!check<T>(L, index, std::forward<Handler>(handler))) {
52+
tracking.use(static_cast<int>(!lua_isnone(L, index)));
53+
return nullopt;
54+
}
55+
return stack_detail::unchecked_get<T>(L, index, tracking);
5856
}
59-
return stack_detail::unchecked_get<T>(L, index, tracking);
6057
}
6158
};
6259

include/sol/stack_check_get_unqualified.hpp

Lines changed: 78 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -45,100 +45,94 @@ namespace stack {
4545

4646
template <typename Handler>
4747
static optional<R> get(lua_State* L, int index, Handler&& handler, record& tracking) {
48-
if (!unqualified_check<T>(L, index, std::forward<Handler>(handler))) {
49-
tracking.use(static_cast<int>(!lua_isnone(L, index)));
50-
return nullopt;
51-
}
52-
return stack_detail::unchecked_unqualified_get<T>(L, index, tracking);
53-
}
54-
};
55-
56-
template <typename T>
57-
struct unqualified_check_getter<T, std::enable_if_t<is_lua_reference<T>::value>> {
58-
template <typename Handler>
59-
static optional<T> get(lua_State* L, int index, Handler&& handler, record& tracking) {
60-
// actually check if it's none here, otherwise
61-
// we'll have a none object inside an optional!
62-
bool success = lua_isnoneornil(L, index) == 0 && stack::check<T>(L, index, no_panic);
63-
if (!success) {
64-
// expected type, actual type
65-
tracking.use(static_cast<int>(success));
66-
handler(L, index, type::poly, type_of(L, index), "");
67-
return nullopt;
68-
}
69-
return stack_detail::unchecked_get<T>(L, index, tracking);
70-
}
71-
};
72-
73-
template <typename T>
74-
struct unqualified_check_getter<T, std::enable_if_t<std::is_integral<T>::value && lua_type_of<T>::value == type::number>> {
75-
template <typename Handler>
76-
static optional<T> get(lua_State* L, int index, Handler&& handler, record& tracking) {
77-
#if SOL_LUA_VERSION >= 503
78-
if (lua_isinteger(L, index) != 0) {
79-
tracking.use(1);
80-
return static_cast<T>(lua_tointeger(L, index));
81-
}
82-
#endif
83-
int isnum = 0;
84-
const lua_Number value = lua_tonumberx(L, index, &isnum);
85-
if (isnum != 0) {
86-
#if (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS) && !(defined(SOL_NO_CHECK_NUMBER_PRECISION) && SOL_NO_CHECK_NUMBER_PRECISION)
87-
const auto integer_value = llround(value);
88-
if (static_cast<lua_Number>(integer_value) == value) {
48+
if constexpr (!meta::meta_detail::is_adl_sol_lua_check_v<T> && !meta::meta_detail::is_adl_sol_lua_get_v<T>) {
49+
if constexpr (is_lua_reference_v<T>) {
50+
// actually check if it's none here, otherwise
51+
// we'll have a none object inside an optional!
52+
bool success = lua_isnoneornil(L, index) == 0 && stack::check<T>(L, index, no_panic);
53+
if (!success) {
54+
// expected type, actual type
55+
tracking.use(static_cast<int>(success));
56+
handler(L, index, type::poly, type_of(L, index), "");
57+
return nullopt;
58+
}
59+
return stack_detail::unchecked_get<T>(L, index, tracking);
60+
}
61+
else if constexpr (std::is_same_v<T, bool>) {
62+
return lua_toboolean(L, index) != 0;
63+
}
64+
else if constexpr (std::is_integral_v<T> && !std::is_same_v<T, bool>) {
65+
#if SOL_LUA_VERSION >= 503
66+
if (lua_isinteger(L, index) != 0) {
67+
tracking.use(1);
68+
return static_cast<T>(lua_tointeger(L, index));
69+
}
70+
#endif
71+
int isnum = 0;
72+
const lua_Number value = lua_tonumberx(L, index, &isnum);
73+
if (isnum != 0) {
74+
#if (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS) && !(defined(SOL_NO_CHECK_NUMBER_PRECISION) && SOL_NO_CHECK_NUMBER_PRECISION)
75+
const auto integer_value = llround(value);
76+
if (static_cast<lua_Number>(integer_value) == value) {
77+
tracking.use(1);
78+
return static_cast<T>(integer_value);
79+
}
80+
#else
81+
tracking.use(1);
82+
return static_cast<T>(value);
83+
#endif
84+
}
85+
const type t = type_of(L, index);
86+
tracking.use(static_cast<int>(t != type::none));
87+
handler(L, index, type::number, t, "not an integer");
88+
return nullopt;
89+
}
90+
else if constexpr(std::is_floating_point_v<T>) {
91+
int isnum = 0;
92+
lua_Number value = lua_tonumberx(L, index, &isnum);
93+
if (isnum == 0) {
94+
type t = type_of(L, index);
95+
tracking.use(static_cast<int>(t != type::none));
96+
handler(L, index, type::number, t, "not a valid floating point number");
97+
return nullopt;
98+
}
8999
tracking.use(1);
90-
return static_cast<T>(integer_value);
100+
return static_cast<T>(value);
101+
}
102+
else if constexpr (std::is_enum_v<T> && !meta::any_same_v<T, meta_function, type>) {
103+
int isnum = 0;
104+
lua_Integer value = lua_tointegerx(L, index, &isnum);
105+
if (isnum == 0) {
106+
type t = type_of(L, index);
107+
tracking.use(static_cast<int>(t != type::none));
108+
handler(L, index, type::number, t, "not a valid enumeration value");
109+
return nullopt;
110+
}
111+
tracking.use(1);
112+
return static_cast<T>(value);
113+
}
114+
else {
115+
if (!unqualified_check<T>(L, index, std::forward<Handler>(handler))) {
116+
tracking.use(static_cast<int>(!lua_isnone(L, index)));
117+
return nullopt;
118+
}
119+
return stack_detail::unchecked_unqualified_get<T>(L, index, tracking);
91120
}
92-
#else
93-
tracking.use(1);
94-
return static_cast<T>(value);
95-
#endif
96-
}
97-
const type t = type_of(L, index);
98-
tracking.use(static_cast<int>(t != type::none));
99-
handler(L, index, type::number, t, "not an integer");
100-
return nullopt;
101-
}
102-
};
103-
104-
template <typename T>
105-
struct unqualified_check_getter<T, std::enable_if_t<std::is_enum<T>::value && !meta::any_same<T, meta_function, type>::value>> {
106-
template <typename Handler>
107-
static optional<T> get(lua_State* L, int index, Handler&& handler, record& tracking) {
108-
int isnum = 0;
109-
lua_Integer value = lua_tointegerx(L, index, &isnum);
110-
if (isnum == 0) {
111-
type t = type_of(L, index);
112-
tracking.use(static_cast<int>(t != type::none));
113-
handler(L, index, type::number, t, "not a valid enumeration value");
114-
return nullopt;
115121
}
116-
tracking.use(1);
117-
return static_cast<T>(value);
118-
}
119-
};
120-
121-
template <typename T>
122-
struct unqualified_check_getter<T, std::enable_if_t<std::is_floating_point<T>::value>> {
123-
template <typename Handler>
124-
static optional<T> get(lua_State* L, int index, Handler&& handler, record& tracking) {
125-
int isnum = 0;
126-
lua_Number value = lua_tonumberx(L, index, &isnum);
127-
if (isnum == 0) {
128-
type t = type_of(L, index);
129-
tracking.use(static_cast<int>(t != type::none));
130-
handler(L, index, type::number, t, "not a valid floating point number");
131-
return nullopt;
122+
else {
123+
if (!unqualified_check<T>(L, index, std::forward<Handler>(handler))) {
124+
tracking.use(static_cast<int>(!lua_isnone(L, index)));
125+
return nullopt;
126+
}
127+
return stack_detail::unchecked_unqualified_get<T>(L, index, tracking);
132128
}
133-
tracking.use(1);
134-
return static_cast<T>(value);
135129
}
136130
};
137131

138132
template <typename T>
139133
struct unqualified_getter<optional<T>> {
140134
static decltype(auto) get(lua_State* L, int index, record& tracking) {
141-
return check_get<T>(L, index, no_panic, tracking);
135+
return stack::unqualified_check_get<T>(L, index, no_panic, tracking);
142136
}
143137
};
144138

0 commit comments

Comments
 (0)