tostring operator doesn't compile if argument is non const

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

tostring operator doesn't compile if argument is non const

Lorenzo Pistone
Hello,
the example in the docs to bind the tostring operator
(http://www.rasterbar.com/products/luabind/docs.html#operators) doesn't
compile. I write it here for reference:

     #include <luabind/luabind.hpp>
     #include <luabind/operator.hpp>
     #include <ostream>
     class number {};
     std::ostream& operator<<(std::ostream& o, number&){ return o; }
     int main(){
         lua_State* L = NULL;
         using namespace luabind;
module(L)[class_<number>("number").def(tostring(self))];
     }

It compiles only if you put use this signature for <<:

std::ostream& operator<<(std::ostream& out, const A&)

Also, I would expect that const_self is required in the def, but it
seems that it doesn't matter. Is this intended behaviour or a bug?

Cheers.

------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: tostring operator doesn't compile if argument is non const

Szymon Gatner
Mutating streaming operator is not idiomatic anyway and will cause problems in other C++ code. Why do you need it to be mutating?


2013/4/10 Lorenzo Pistone <[hidden email]>
Hello,
the example in the docs to bind the tostring operator
(http://www.rasterbar.com/products/luabind/docs.html#operators) doesn't
compile. I write it here for reference:

     #include <luabind/luabind.hpp>
     #include <luabind/operator.hpp>
     #include <ostream>
     class number {};
     std::ostream& operator<<(std::ostream& o, number&){ return o; }
     int main(){
         lua_State* L = NULL;
         using namespace luabind;
module(L)[class_<number>("number").def(tostring(self))];
     }

It compiles only if you put use this signature for <<:

std::ostream& operator<<(std::ostream& out, const A&)

Also, I would expect that const_self is required in the def, but it
seems that it doesn't matter. Is this intended behaviour or a bug?

Cheers.

------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user



--
Szymon Gatner
The Lordz Games Studio
www.thelordzgamesstudio.com

------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: tostring operator doesn't compile if argument is non const

Lorenzo Pistone
Well, the code I'm trying to build has them, and I agree that it's not a wise choice in the C++ side, but if I have to export that API I would like to do it correctly.

On 04/18/2013 09:50 AM, Szymon Gatner wrote:
Mutating streaming operator is not idiomatic anyway and will cause problems in other C++ code. Why do you need it to be mutating?


2013/4/10 Lorenzo Pistone <[hidden email]>
Hello,
the example in the docs to bind the tostring operator
(http://www.rasterbar.com/products/luabind/docs.html#operators) doesn't
compile. I write it here for reference:

     #include <luabind/luabind.hpp>
     #include <luabind/operator.hpp>
     #include <ostream>
     class number {};
     std::ostream& operator<<(std::ostream& o, number&){ return o; }
     int main(){
         lua_State* L = NULL;
         using namespace luabind;
module(L)[class_<number>("number").def(tostring(self))];
     }

It compiles only if you put use this signature for <<:

std::ostream& operator<<(std::ostream& out, const A&)

Also, I would expect that const_self is required in the def, but it
seems that it doesn't matter. Is this intended behaviour or a bug?

Cheers.

------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user



--
Szymon Gatner
The Lordz Games Studio
www.thelordzgamesstudio.com


------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter


_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user