One day I'll have a perfect release...

This commit is contained in:
ThePhD 2016-08-11 11:36:39 -04:00
parent f85dba2a69
commit ff8ac8a6d4
2 changed files with 23 additions and 1 deletions

View File

@ -182,7 +182,7 @@ namespace sol {
template<typename T> template<typename T>
struct pusher<T, std::enable_if_t<std::is_base_of<reference, T>::value || std::is_base_of<stack_reference, T>::value>> { struct pusher<T, std::enable_if_t<std::is_base_of<reference, T>::value || std::is_base_of<stack_reference, T>::value>> {
static int push(lua_State*, T& ref) { static int push(lua_State*, const T& ref) {
return ref.push(); return ref.push();
} }

View File

@ -560,3 +560,25 @@ TEST_CASE("optional/left-out-args", "Make sure arguments can be left out of opti
)"); )");
); );
} }
TEST_CASE("pusher/constness", "Make sure more types can handle being const and junk") {
struct Foo {
Foo(sol::function& f) : _f(f) {}
const sol::function& _f;
const sol::function& f() const { return _f; }
};
sol::state lua;
lua.new_usertype<Foo>("Foo",
sol::call_constructor, sol::no_constructor,
"f", &Foo::f
);
lua["func"] = []() { return 20; };
lua["foo"] = Foo(lua["func"]);
Foo& foo = lua["foo"];
int x = foo.f()();
REQUIRE(x == 20);
}