Some minor fixes and updates

This commit is contained in:
ThePhD 2016-09-29 03:29:48 -04:00
parent 471b5870e2
commit 72a445ff6a
5 changed files with 158 additions and 148 deletions

View File

@ -74,6 +74,7 @@ namespace sol {
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
return stack::check<T>(base_t::lua_state(), -1, no_panic); return stack::check<T>(base_t::lua_state(), -1, no_panic);
} }
template <bool invert_and_pop = false> template <bool invert_and_pop = false>
basic_object(std::integral_constant<bool, invert_and_pop>, lua_State* L, int index = -1) noexcept : base_t(L, index) { basic_object(std::integral_constant<bool, invert_and_pop>, lua_State* L, int index = -1) noexcept : base_t(L, index) {
if (invert_and_pop) { if (invert_and_pop) {
@ -90,6 +91,14 @@ namespace sol {
basic_object(basic_object&&) = default; basic_object(basic_object&&) = default;
basic_object& operator=(const basic_object&) = default; basic_object& operator=(const basic_object&) = default;
basic_object& operator=(basic_object&&) = default; basic_object& operator=(basic_object&&) = default;
basic_object& operator=(const base_t& b) {
base_t::operator=(b);
return *this;
}
basic_object& operator=(base_t&& b) {
base_t::operator=(std::move(b));
return *this;
}
basic_object(const stack_reference& r) noexcept : basic_object(r.lua_state(), r.stack_index()) {} basic_object(const stack_reference& r) noexcept : basic_object(r.lua_state(), r.stack_index()) {}
basic_object(stack_reference&& r) noexcept : basic_object(r.lua_state(), r.stack_index()) {} basic_object(stack_reference&& r) noexcept : basic_object(r.lua_state(), r.stack_index()) {}
basic_object(lua_State* L, int index = -1) noexcept : base_t(L, index) {} basic_object(lua_State* L, int index = -1) noexcept : base_t(L, index) {}

View File

@ -334,15 +334,15 @@ namespace sol {
struct getter<wchar_t> { struct getter<wchar_t> {
static wchar_t get(lua_State* L, int index, record& tracking) { static wchar_t get(lua_State* L, int index, record& tracking) {
auto str = getter<std::wstring>{}.get(L, index, tracking); auto str = getter<std::wstring>{}.get(L, index, tracking);
return str.size() > 0 ? str[0] : '\0'; return str.size() > 0 ? str[0] : wchar_t(0);
} }
}; };
template<> template<>
struct getter<char16_t> { struct getter<char16_t> {
static char get(lua_State* L, int index, record& tracking) { static char16_t get(lua_State* L, int index, record& tracking) {
auto str = getter<std::u16string>{}.get(L, index, tracking); auto str = getter<std::u16string>{}.get(L, index, tracking);
return str.size() > 0 ? str[0] : '\0'; return str.size() > 0 ? str[0] : char16_t(0);
} }
}; };
@ -350,7 +350,7 @@ namespace sol {
struct getter<char32_t> { struct getter<char32_t> {
static char32_t get(lua_State* L, int index, record& tracking) { static char32_t get(lua_State* L, int index, record& tracking) {
auto str = getter<std::u32string>{}.get(L, index, tracking); auto str = getter<std::u32string>{}.get(L, index, tracking);
return str.size() > 0 ? str[0] : '\0'; return str.size() > 0 ? str[0] : char32_t(0);
} }
}; };
#endif // codecvt header support #endif // codecvt header support

View File

@ -85,7 +85,7 @@ namespace sol {
}; };
template <typename... Tn> template <typename... Tn>
struct tie_size<::sol::tie_t<Tn...>> : ::std::tuple_size<::std::tuple<Tn...>> { }; struct tie_size< tie_t<Tn...> > : std::tuple_size< std::tuple<Tn...> > { };
namespace adl_barrier_detail { namespace adl_barrier_detail {
template <typename... Tn> template <typename... Tn>

View File

@ -138,8 +138,8 @@ namespace sol {
typedef std::shared_ptr<T> actual_type; typedef std::shared_ptr<T> actual_type;
static const bool value = true; static const bool value = true;
static bool is_null(const actual_type& value) { static bool is_null(const actual_type& p) {
return value == nullptr; return p == nullptr;
} }
static type* get(const actual_type& p) { static type* get(const actual_type& p) {
@ -153,8 +153,8 @@ namespace sol {
typedef std::unique_ptr<T, D> actual_type; typedef std::unique_ptr<T, D> actual_type;
static const bool value = true; static const bool value = true;
static bool is_null(const actual_type& value) { static bool is_null(const actual_type& p) {
return value == nullptr; return p == nullptr;
} }
static type* get(const actual_type& p) { static type* get(const actual_type& p) {

View File

@ -349,7 +349,6 @@ TEST_CASE("usertype/usertype-utility-derived", "usertype classes must play nice
lua.set_usertype(derivedusertype); lua.set_usertype(derivedusertype);
lua.script("derived = Derived.new(7)"); lua.script("derived = Derived.new(7)");
Derived& derived = lua["derived"];
lua.script("dgn = derived:get_num()\n" lua.script("dgn = derived:get_num()\n"
"print(dgn)"); "print(dgn)");
lua.script("dgn10 = derived:get_num_10()\n" lua.script("dgn10 = derived:get_num_10()\n"
@ -608,6 +607,8 @@ TEST_CASE("usertype/destructor-tests", "Show that proper copies / destruction ha
REQUIRE(created == 4); REQUIRE(created == 4);
REQUIRE(destroyed == 0); REQUIRE(destroyed == 0);
REQUIRE(std::addressof(x1) == std::addressof(x1ref)); REQUIRE(std::addressof(x1) == std::addressof(x1ref));
REQUIRE(std::addressof(x1copyref) != std::addressof(x1));
REQUIRE(std::addressof(x2copyref) != std::addressof(x2));
} }
REQUIRE(created == 4); REQUIRE(created == 4);
REQUIRE(destroyed == 4); REQUIRE(destroyed == 4);