diff --git a/sol/proxy.hpp b/sol/proxy.hpp index bd7a083b..aa0d6129 100644 --- a/sol/proxy.hpp +++ b/sol/proxy.hpp @@ -64,35 +64,39 @@ public: tbl.set( key, std::forward( other ) ); } - operator nil_t ( ) { + operator nil_t ( ) const { return get( ); } - operator bool( ) { - return get( ); - } - - operator std::string( ) { - return get( ); - } - - operator object( ) { + operator object( ) const { return get( ); } - operator function( ) { + operator function( ) const { return get( ); } - operator double( ) { + operator std::string( ) const { + return get( ); + } + + template + operator bool( ) const { + return get( ); + } + + template + operator double( ) const { return get( ); } - operator float( ) { + template + operator float( ) const { return get( ); } - operator int( ) { + template + operator int( ) const { return get( ); } @@ -103,23 +107,23 @@ public: }; template -bool operator== ( T&& left, const proxy& right ) { - return right.get>( ) == left; +inline bool operator== ( T&& left, const proxy& right ) { + return left == right.template get>( ); } template -bool operator== ( const proxy& right, T&& left ) { - return right.get>( ) == left; +inline bool operator== ( const proxy& right, T&& left ) { + return right.template get>( ) == left; } template -bool operator!= ( T&& left, const proxy& right ) { - return right.get>( ) != left; +inline bool operator!= ( T&& left, const proxy& right ) { + return right.template get>( ) != left; } template -bool operator!= ( const proxy& right, T&& left ) { - return right.get>( ) != left; +inline bool operator!= ( const proxy& right, T&& left ) { + return right.template get>( ) != left; } } // sol \ No newline at end of file diff --git a/tests.cpp b/tests.cpp index 355a9546..3a40f181 100644 --- a/tests.cpp +++ b/tests.cpp @@ -285,6 +285,7 @@ TEST_CASE("tables/operator[]", "Check if operator[] retrieval and setting works REQUIRE(bar == "hello world"); REQUIRE(foo == 20); // test operator= for stringification + // errors due to ambiguous operators bar = lua["bar"]; // basic setting @@ -300,7 +301,7 @@ TEST_CASE("tables/operator[]", "Check if operator[] retrieval and setting works REQUIRE_NOTHROW(lua.script("assert(test(10, 11, \"hello\") == 11)")); // function retrieval - sol::function test = lua["test"]; + sol::function test = lua[ "test" ]; REQUIRE(test.call(10, 11, "hello") == 11); // setting a lambda @@ -311,15 +312,15 @@ TEST_CASE("tables/operator[]", "Check if operator[] retrieval and setting works REQUIRE_NOTHROW(lua.script("assert(lamb(220) == 440)")); // function retrieval of a lambda - sol::function lamb = lua["lamb"]; + sol::function lamb;// = lua[ "lamb" ]; REQUIRE(lamb.call(220) == 440); // test const table retrieval auto assert1 = [](const sol::table& t) { std::string a = t["foo"]; - int b = t["bar"]; + int b = t["bar"]; std::cout << a << ',' << b << '\n'; }; REQUIRE_NOTHROW(assert1(lua.global_table())); -} \ No newline at end of file +}