Skip to content

Commit

Permalink
fix problem with instantiations of abstract classes in optional refer…
Browse files Browse the repository at this point in the history
…ence
  • Loading branch information
ThePhD committed Sep 11, 2016
1 parent edb8eac commit 5dface2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Optional
12 changes: 6 additions & 6 deletions single/sol/sol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

// This file was generated with a script.
// Generated 2016-09-04 15:42:29.271382 UTC
// This header was generated with sol v2.12.2 (revision cb0116a)
// Generated 2016-09-11 00:47:45.107316 UTC
// This header was generated with sol v2.12.3 (revision edb8eac)
// https://github.com/ThePhD/sol2

#ifndef SOL_SINGLE_INCLUDE_HPP
Expand Down Expand Up @@ -1442,10 +1442,10 @@ class optional<T&>
return ref != nullptr;
}

template <class V>
constexpr typename ::std::decay<T>::type value_or(V&& v) const
template <typename V>
constexpr T& value_or(V&& v) const
{
return *this ? **this : detail_::convert<typename ::std::decay<T>::type>(constexpr_forward<V>(v));
return *this ? **this : detail_::convert<T&>(constexpr_forward<V>(v));
}
};

Expand Down Expand Up @@ -9382,7 +9382,7 @@ namespace sol {
namespace usertype_detail {
struct no_comp {
template <typename A, typename B>
bool operator()(A&&, B&&) {
bool operator()(A&&, B&&) const {
return false;
}
};
Expand Down
2 changes: 1 addition & 1 deletion sol/usertype_metatable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace sol {
namespace usertype_detail {
struct no_comp {
template <typename A, typename B>
bool operator()(A&&, B&&) {
bool operator()(A&&, B&&) const {
return false;
}
};
Expand Down
22 changes: 22 additions & 0 deletions test_usertypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ class Derived : public Base {
}
};

class abstract_A {
public:
virtual void a() = 0;
};

class abstract_B : public abstract_A {
public:
virtual void a() override {
INFO("overridden a() in B : public A - BARK");
}
};

struct Vec {
float x, y, z;
Vec(float x, float y, float z) : x{ x }, y{ y }, z{ z } {}
Expand Down Expand Up @@ -1405,3 +1417,13 @@ TEST_CASE("usertype/unique_usertype-check", "make sure unique usertypes don't ge
my_func(std::make_shared<Entity>());
});
}

TEST_CASE("usertype/abstract-base-class", "Ensure that abstract base classes and such can be registered") {

sol::state lua;
lua.new_usertype<abstract_A>("A", "a", &abstract_A::a);
lua.new_usertype<abstract_B>("B", sol::base_classes, sol::bases<abstract_A>());
lua.script(R"(local b = B.new()
b:a()
)");
}

0 comments on commit 5dface2

Please sign in to comment.