Fiiiiixes.

This commit is contained in:
ThePhD 2018-11-21 07:34:32 -05:00
parent 157db07a56
commit 55e92056c1
No known key found for this signature in database
GPG Key ID: 1509DB1C0F702BFA
11 changed files with 259 additions and 91 deletions

View File

@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This file was generated with a script. // This file was generated with a script.
// Generated 2018-11-10 19:02:00.192743 UTC // Generated 2018-11-21 12:34:11.276133 UTC
// This header was generated with sol v2.20.5 (revision 2cfbc8c) // This header was generated with sol v2.20.5 (revision 157db07)
// https://github.com/ThePhD/sol2 // https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_HPP #ifndef SOL_SINGLE_INCLUDE_HPP
@ -7147,6 +7147,9 @@ namespace sol {
#include <vector> #include <vector>
#include <forward_list> #include <forward_list>
#include <algorithm> #include <algorithm>
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
#include <optional>
#endif // C++17
namespace sol { namespace sol {
namespace detail { namespace detail {
@ -7928,6 +7931,13 @@ namespace sol {
return stack_detail::unchecked_unqualified_get<optional<T>>(L, index, tracking); return stack_detail::unchecked_unqualified_get<optional<T>>(L, index, tracking);
} }
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
template <typename T>
inline decltype(auto) tagged_unqualified_get(types<std::optional<T>>, lua_State* L, int index, record& tracking) {
return stack_detail::unchecked_unqualified_get<std::optional<T>>(L, index, tracking);
}
#endif // shitty optional
template <typename T> template <typename T>
inline auto tagged_get(types<T>, lua_State* L, int index, record& tracking) -> decltype(stack_detail::unchecked_get<T>(L, index, tracking)) { inline auto tagged_get(types<T>, lua_State* L, int index, record& tracking) -> decltype(stack_detail::unchecked_get<T>(L, index, tracking)) {
if (is_lua_reference<T>::value) { if (is_lua_reference<T>::value) {
@ -7941,6 +7951,14 @@ namespace sol {
inline decltype(auto) tagged_get(types<optional<T>>, lua_State* L, int index, record& tracking) { inline decltype(auto) tagged_get(types<optional<T>>, lua_State* L, int index, record& tracking) {
return stack_detail::unchecked_get<optional<T>>(L, index, tracking); return stack_detail::unchecked_get<optional<T>>(L, index, tracking);
} }
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
template <typename T>
inline decltype(auto) tagged_get(types<std::optional<T>>, lua_State* L, int index, record& tracking) {
return stack_detail::unchecked_get<std::optional<T>>(L, index, tracking);
}
#endif // shitty optional
#else #else
template <typename T> template <typename T>
inline decltype(auto) tagged_unqualified_get(types<T>, lua_State* L, int index, record& tracking) { inline decltype(auto) tagged_unqualified_get(types<T>, lua_State* L, int index, record& tracking) {
@ -9295,7 +9313,11 @@ namespace stack {
if (i == 0) { if (i == 0) {
break; break;
} }
#if defined(LUA_NILINTABLE) && LUA_NILINTABLE
lua_pop(L, vi);
#else
lua_pop(L, (vi + 1)); lua_pop(L, (vi + 1));
#endif
return arr; return arr;
} }
} }
@ -10006,6 +10028,7 @@ namespace stack {
}; };
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
#if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT #if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
template <typename... Tn> template <typename... Tn>
struct getter<std::variant<Tn...>> { struct getter<std::variant<Tn...>> {
@ -10101,6 +10124,9 @@ namespace stack {
// beginning of sol/stack_check_get_unqualified.hpp // beginning of sol/stack_check_get_unqualified.hpp
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
#endif // C++17
namespace sol { namespace sol {
namespace stack { namespace stack {
template <typename T, typename> template <typename T, typename>
@ -10207,6 +10233,17 @@ namespace stack {
}; };
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
template <typename T>
struct getter<std::optional<T>> {
static std::optional<T> get(lua_State* L, int index, record& tracking) {
if (!unqualified_check<T>(L, index, no_panic)) {
tracking.use(static_cast<int>(!lua_isnone(L, index)));
return std::nullopt;
}
return stack_detail::unchecked_unqualified_get<T>(L, index, tracking);
}
};
#if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT #if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
template <typename... Tn> template <typename... Tn>
struct check_getter<std::variant<Tn...>> { struct check_getter<std::variant<Tn...>> {
@ -10846,7 +10883,7 @@ namespace stack {
template <size_t N> template <size_t N>
struct pusher<char[N]> { struct pusher<char[N]> {
static int push(lua_State* L, const char (&str)[N]) { static int push(lua_State* L, const char (&str)[N]) {
lua_pushlstring(L, str, N - 1); lua_pushlstring(L, str, std::char_traits<char>::length(str));
return 1; return 1;
} }
@ -11125,7 +11162,7 @@ namespace stack {
template <size_t N> template <size_t N>
struct pusher<wchar_t[N]> { struct pusher<wchar_t[N]> {
static int push(lua_State* L, const wchar_t (&str)[N]) { static int push(lua_State* L, const wchar_t (&str)[N]) {
return push(L, str, N - 1); return push(L, str, std::char_traits<wchar_t>::length(str));
} }
static int push(lua_State* L, const wchar_t (&str)[N], std::size_t sz) { static int push(lua_State* L, const wchar_t (&str)[N], std::size_t sz) {
@ -11136,7 +11173,7 @@ namespace stack {
template <size_t N> template <size_t N>
struct pusher<char16_t[N]> { struct pusher<char16_t[N]> {
static int push(lua_State* L, const char16_t (&str)[N]) { static int push(lua_State* L, const char16_t (&str)[N]) {
return push(L, str, N - 1); return push(L, str, std::char_traits<char16_t>::length(str));
} }
static int push(lua_State* L, const char16_t (&str)[N], std::size_t sz) { static int push(lua_State* L, const char16_t (&str)[N], std::size_t sz) {
@ -11147,7 +11184,7 @@ namespace stack {
template <size_t N> template <size_t N>
struct pusher<char32_t[N]> { struct pusher<char32_t[N]> {
static int push(lua_State* L, const char32_t (&str)[N]) { static int push(lua_State* L, const char32_t (&str)[N]) {
return push(L, str, N - 1); return push(L, str, std::char_traits<char32_t>::length(str));
} }
static int push(lua_State* L, const char32_t (&str)[N], std::size_t sz) { static int push(lua_State* L, const char32_t (&str)[N], std::size_t sz) {
@ -11263,6 +11300,17 @@ namespace stack {
}; };
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
template <typename O>
struct pusher<std::optional<O>> {
template <typename T>
static int push(lua_State* L, T&& t) {
if (t == std::nullopt) {
return stack::push(L, nullopt);
}
return stack::push(L, static_cast<std::conditional_t<std::is_lvalue_reference<T>::value, O&, O&&>>(t.value()));
}
};
#if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT #if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
namespace stack_detail { namespace stack_detail {
@ -14068,7 +14116,7 @@ namespace function_detail {
namespace sol { namespace sol {
namespace function_detail { namespace function_detail {
template <typename Func, bool is_yielding> template <typename Func, bool is_yielding, bool no_trampoline>
struct functor_function { struct functor_function {
typedef std::decay_t<meta::unwrap_unqualified_t<Func>> function_type; typedef std::decay_t<meta::unwrap_unqualified_t<Func>> function_type;
function_type fx; function_type fx;
@ -14089,9 +14137,14 @@ namespace function_detail {
} }
int operator()(lua_State* L) { int operator()(lua_State* L) {
if (!no_trampoline) {
auto f = [&](lua_State*) -> int { return this->call(L); }; auto f = [&](lua_State*) -> int { return this->call(L); };
return detail::trampoline(L, f); return detail::trampoline(L, f);
} }
else {
return call(L);
}
}
}; };
template <typename T, typename Function, bool is_yielding> template <typename T, typename Function, bool is_yielding>
@ -14368,7 +14421,7 @@ namespace sol {
template <bool is_yielding, typename... Sig, typename Fx, typename... Args> template <bool is_yielding, typename... Sig, typename Fx, typename... Args>
static void select_convertible(std::false_type, types<Sig...>, lua_State* L, Fx&& fx, Args&&... args) { static void select_convertible(std::false_type, types<Sig...>, lua_State* L, Fx&& fx, Args&&... args) {
typedef std::remove_pointer_t<std::decay_t<Fx>> clean_fx; typedef std::remove_pointer_t<std::decay_t<Fx>> clean_fx;
typedef function_detail::functor_function<clean_fx, is_yielding> F; typedef function_detail::functor_function<clean_fx, is_yielding, true> F;
set_fx<false, F>(L, std::forward<Fx>(fx), std::forward<Args>(args)...); set_fx<false, F>(L, std::forward<Fx>(fx), std::forward<Args>(args)...);
} }
@ -18850,6 +18903,9 @@ namespace sol {
if (member != nullptr) { if (member != nullptr) {
return (member)(L, static_cast<void*>(&f), static_cast<usertype_metatable_core&>(f), runtime_target); return (member)(L, static_cast<void*>(&f), static_cast<usertype_metatable_core&>(f), runtime_target);
} }
if (is_meta_bound && toplevel && !is_index) {
return usertype_detail::metatable_new_index<T, false>(L);
}
string_view accessor = stack::get<string_view>(L, keyidx); string_view accessor = stack::get<string_view>(L, keyidx);
int ret = 0; int ret = 0;
bool found = false; bool found = false;
@ -21825,7 +21881,12 @@ namespace sol {
call_status stats = call_status::yielded; call_status stats = call_status::yielded;
void luacall(std::ptrdiff_t argcount, std::ptrdiff_t) { void luacall(std::ptrdiff_t argcount, std::ptrdiff_t) {
#if SOL_LUA_VERSION >= 504
int nres;
stats = static_cast<call_status>(lua_resume(lua_state(), nullptr, static_cast<int>(argcount), &nres));
#else
stats = static_cast<call_status>(lua_resume(lua_state(), nullptr, static_cast<int>(argcount))); stats = static_cast<call_status>(lua_resume(lua_state(), nullptr, static_cast<int>(argcount)));
#endif
} }
template <std::size_t... I, typename... Ret> template <std::size_t... I, typename... Ret>

View File

@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This file was generated with a script. // This file was generated with a script.
// Generated 2018-11-10 19:02:00.404748 UTC // Generated 2018-11-21 12:34:11.544452 UTC
// This header was generated with sol v2.20.5 (revision 2cfbc8c) // This header was generated with sol v2.20.5 (revision 157db07)
// https://github.com/ThePhD/sol2 // https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP #ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP

View File

@ -41,7 +41,12 @@ namespace sol {
call_status stats = call_status::yielded; call_status stats = call_status::yielded;
void luacall(std::ptrdiff_t argcount, std::ptrdiff_t) { void luacall(std::ptrdiff_t argcount, std::ptrdiff_t) {
#if SOL_LUA_VERSION >= 504
int nres;
stats = static_cast<call_status>(lua_resume(lua_state(), nullptr, static_cast<int>(argcount), &nres));
#else
stats = static_cast<call_status>(lua_resume(lua_state(), nullptr, static_cast<int>(argcount))); stats = static_cast<call_status>(lua_resume(lua_state(), nullptr, static_cast<int>(argcount)));
#endif
} }
template <std::size_t... I, typename... Ret> template <std::size_t... I, typename... Ret>

View File

@ -46,7 +46,7 @@ namespace sol {
template <bool is_yielding, typename... Sig, typename Fx, typename... Args> template <bool is_yielding, typename... Sig, typename Fx, typename... Args>
static void select_convertible(std::false_type, types<Sig...>, lua_State* L, Fx&& fx, Args&&... args) { static void select_convertible(std::false_type, types<Sig...>, lua_State* L, Fx&& fx, Args&&... args) {
typedef std::remove_pointer_t<std::decay_t<Fx>> clean_fx; typedef std::remove_pointer_t<std::decay_t<Fx>> clean_fx;
typedef function_detail::functor_function<clean_fx, is_yielding> F; typedef function_detail::functor_function<clean_fx, is_yielding, true> F;
set_fx<false, F>(L, std::forward<Fx>(fx), std::forward<Args>(args)...); set_fx<false, F>(L, std::forward<Fx>(fx), std::forward<Args>(args)...);
} }

View File

@ -28,7 +28,7 @@
namespace sol { namespace sol {
namespace function_detail { namespace function_detail {
template <typename Func, bool is_yielding> template <typename Func, bool is_yielding, bool no_trampoline>
struct functor_function { struct functor_function {
typedef std::decay_t<meta::unwrap_unqualified_t<Func>> function_type; typedef std::decay_t<meta::unwrap_unqualified_t<Func>> function_type;
function_type fx; function_type fx;
@ -49,9 +49,14 @@ namespace function_detail {
} }
int operator()(lua_State* L) { int operator()(lua_State* L) {
if (!no_trampoline) {
auto f = [&](lua_State*) -> int { return this->call(L); }; auto f = [&](lua_State*) -> int { return this->call(L); };
return detail::trampoline(L, f); return detail::trampoline(L, f);
} }
else {
return call(L);
}
}
}; };
template <typename T, typename Function, bool is_yielding> template <typename T, typename Function, bool is_yielding>

View File

@ -28,8 +28,14 @@
#include "stack_get.hpp" #include "stack_get.hpp"
#include "stack_check.hpp" #include "stack_check.hpp"
#include "optional.hpp" #include "optional.hpp"
#include <cstdlib> #include <cstdlib>
#include <cmath> #include <cmath>
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
#include <optional>
#endif // C++17
namespace sol { namespace sol {
namespace stack { namespace stack {
@ -137,6 +143,17 @@ namespace stack {
}; };
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
template <typename T>
struct getter<std::optional<T>> {
static std::optional<T> get(lua_State* L, int index, record& tracking) {
if (!unqualified_check<T>(L, index, no_panic)) {
tracking.use(static_cast<int>(!lua_isnone(L, index)));
return std::nullopt;
}
return stack_detail::unchecked_unqualified_get<T>(L, index, tracking);
}
};
#if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT #if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
template <typename... Tn> template <typename... Tn>
struct check_getter<std::variant<Tn...>> { struct check_getter<std::variant<Tn...>> {

View File

@ -40,6 +40,9 @@
#include <forward_list> #include <forward_list>
#include <string> #include <string>
#include <algorithm> #include <algorithm>
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
#include <optional>
#endif // C++17
namespace sol { namespace sol {
namespace detail { namespace detail {
@ -821,6 +824,13 @@ namespace sol {
return stack_detail::unchecked_unqualified_get<optional<T>>(L, index, tracking); return stack_detail::unchecked_unqualified_get<optional<T>>(L, index, tracking);
} }
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
template <typename T>
inline decltype(auto) tagged_unqualified_get(types<std::optional<T>>, lua_State* L, int index, record& tracking) {
return stack_detail::unchecked_unqualified_get<std::optional<T>>(L, index, tracking);
}
#endif // shitty optional
template <typename T> template <typename T>
inline auto tagged_get(types<T>, lua_State* L, int index, record& tracking) -> decltype(stack_detail::unchecked_get<T>(L, index, tracking)) { inline auto tagged_get(types<T>, lua_State* L, int index, record& tracking) -> decltype(stack_detail::unchecked_get<T>(L, index, tracking)) {
if (is_lua_reference<T>::value) { if (is_lua_reference<T>::value) {
@ -834,6 +844,14 @@ namespace sol {
inline decltype(auto) tagged_get(types<optional<T>>, lua_State* L, int index, record& tracking) { inline decltype(auto) tagged_get(types<optional<T>>, lua_State* L, int index, record& tracking) {
return stack_detail::unchecked_get<optional<T>>(L, index, tracking); return stack_detail::unchecked_get<optional<T>>(L, index, tracking);
} }
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
template <typename T>
inline decltype(auto) tagged_get(types<std::optional<T>>, lua_State* L, int index, record& tracking) {
return stack_detail::unchecked_get<std::optional<T>>(L, index, tracking);
}
#endif // shitty optional
#else #else
template <typename T> template <typename T>
inline decltype(auto) tagged_unqualified_get(types<T>, lua_State* L, int index, record& tracking) { inline decltype(auto) tagged_unqualified_get(types<T>, lua_State* L, int index, record& tracking) {

View File

@ -171,7 +171,11 @@ namespace stack {
if (i == 0) { if (i == 0) {
break; break;
} }
#if defined(LUA_NILINTABLE) && LUA_NILINTABLE
lua_pop(L, vi);
#else
lua_pop(L, (vi + 1)); lua_pop(L, (vi + 1));
#endif
return arr; return arr;
} }
} }
@ -882,6 +886,8 @@ namespace stack {
}; };
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
#if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT #if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
template <typename... Tn> template <typename... Tn>
struct getter<std::variant<Tn...>> { struct getter<std::variant<Tn...>> {

View File

@ -593,6 +593,9 @@ namespace sol {
if (member != nullptr) { if (member != nullptr) {
return (member)(L, static_cast<void*>(&f), static_cast<usertype_metatable_core&>(f), runtime_target); return (member)(L, static_cast<void*>(&f), static_cast<usertype_metatable_core&>(f), runtime_target);
} }
if (is_meta_bound && toplevel && !is_index) {
return usertype_detail::metatable_new_index<T, false>(L);
}
string_view accessor = stack::get<string_view>(L, keyidx); string_view accessor = stack::get<string_view>(L, keyidx);
int ret = 0; int ret = 0;
bool found = false; bool found = false;

View File

@ -1635,8 +1635,6 @@ TEST_CASE("usertype/runtime-extensibility", "Check if usertypes are runtime exte
class derived_b : public base_a { class derived_b : public base_a {
}; };
SECTION("just functions") { SECTION("just functions") {
sol::state lua; sol::state lua;
lua.open_libraries(sol::lib::base); lua.open_libraries(sol::lib::base);
@ -1747,8 +1745,12 @@ end
REQUIRE(pfr0.valid()); REQUIRE(pfr0.valid());
auto pfr1 = lua.safe_script("function B:c() print('B') return 2 end", sol::script_pass_on_error); auto pfr1 = lua.safe_script("function B:c() print('B') return 2 end", sol::script_pass_on_error);
REQUIRE(pfr1.valid()); REQUIRE(pfr1.valid());
auto pfr2 = lua.safe_script("local obja = A.new() local objb = B.new() assert(obja:c() == 1) assert(objb:c() == 2)", sol::script_pass_on_error); auto pfr2 = lua.safe_script("obja = A.new() objb = B.new()", sol::script_default_on_error);
REQUIRE(pfr2.valid()); REQUIRE(pfr2.valid());
auto pfr3 = lua.safe_script("assert(obja:c() == 1)", sol::script_default_on_error);
REQUIRE(pfr3.valid());
auto pfr4 = lua.safe_script("assert(objb:c() == 2)", sol::script_default_on_error);
REQUIRE(pfr4.valid());
} }
} }

View File

@ -72,10 +72,14 @@ TEST_CASE("utility/variant", "test that variant can be round-tripped") {
return v == 2; return v == 2;
}); });
lua["v"] = std::variant<float, int, std::string>(2); lua["v"] = std::variant<float, int, std::string>(2);
REQUIRE_NOTHROW([&]() { {
lua.safe_script("assert(f(v))"); auto result = lua.safe_script("assert(f(v))", sol::script_pass_on_error);
lua.safe_script("assert(g(v))"); REQUIRE(result.valid());
}()); };
{
auto result = lua.safe_script("assert(g(v))", sol::script_pass_on_error);
REQUIRE(result.valid());
};
} }
SECTION("throws") { SECTION("throws") {
sol::state lua; sol::state lua;
@ -103,6 +107,53 @@ TEST_CASE("utility/variant", "test that variant can be round-tripped") {
#endif // C++17 #endif // C++17
} }
TEST_CASE("utility/optional", "test that shit optional can be round-tripped") {
#ifdef SOL_CXX17_FEATURES
SECTION("okay") {
sol::state lua;
lua.open_libraries(sol::lib::base);
lua.set_function("f", [](int v) {
return v == 2;
});
lua.set_function("g", [](std::optional<int> vv) {
return vv && *vv == 2;
});
lua["v"] = std::optional<int>(2);
{
auto result = lua.safe_script("assert(f(v))", sol::script_pass_on_error);
REQUIRE(result.valid());
}
{
auto result = lua.safe_script("assert(g(v))", sol::script_pass_on_error);
REQUIRE(result.valid());
}
}
SECTION("throws") {
sol::state lua;
lua.open_libraries(sol::lib::base);
lua.set_function("f", [](int v) {
return v == 2;
});
lua.set_function("g", [](std::optional<int> vv) {
return vv && *vv == 2;
});
lua["v"] = std::optional<int>(std::nullopt);
{
auto result = lua.safe_script("assert(f(v))", sol::script_pass_on_error);
REQUIRE_FALSE(result.valid());
};
{
auto result = lua.safe_script("assert(g(v))", sol::script_pass_on_error);
REQUIRE_FALSE(result.valid());
};
}
#else
REQUIRE(true);
#endif // C++17
}
TEST_CASE("utility/string_view", "test that string_view can be taken as an argument") { TEST_CASE("utility/string_view", "test that string_view can be taken as an argument") {
#ifdef SOL_CXX17_FEATURES #ifdef SOL_CXX17_FEATURES
sol::state lua; sol::state lua;