mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
One day I'll have a perfect release...
This commit is contained in:
parent
f85dba2a69
commit
ff8ac8a6d4
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
22
tests.cpp
22
tests.cpp
|
@ -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);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user