From ff8ac8a6d4576d085670ee1134bccd06a3d090e5 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Thu, 11 Aug 2016 11:36:39 -0400 Subject: [PATCH] One day I'll have a perfect release... --- sol/stack_push.hpp | 2 +- tests.cpp | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/sol/stack_push.hpp b/sol/stack_push.hpp index ab253c0b..30aac967 100644 --- a/sol/stack_push.hpp +++ b/sol/stack_push.hpp @@ -182,7 +182,7 @@ namespace sol { template struct pusher::value || std::is_base_of::value>> { - static int push(lua_State*, T& ref) { + static int push(lua_State*, const T& ref) { return ref.push(); } diff --git a/tests.cpp b/tests.cpp index 92d76b3d..098dd103 100644 --- a/tests.cpp +++ b/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", + 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); +}