Re: Overriding __concat behavior

Teto <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
I succeeded in implenting the behavior. See the enclosed file.
It basically works like tostring except there are 2 arguments:

I define them like this:
.def(
luabind::concat_operator(luabind::const_self,luabind::other<std::string>() )
)
.def( luabind::concat_operator(luabind::const_self,int() ) )

What would be cool would be to register automatically the 2nd type so that
we could write
.def( luabind::concat_operator(luabind::const_self)) only.

I hope concat operator will be added to next release even if it's not my
code.

Matt

On Wed, Mar 23, 2011 at 7:48 PM, Teto <[email protected]> wrote:

> I don't know if it's relevant but the member function "__concat" I
> bind is called, luabind just tells me that it has the wrong prototype:
> "No matching overload found, candidates:
> std::string __concat(CBattery&,std::string,std::string);"
>
> Is there any way to have an acceptable prototype (like void*,void*). I
> will have a look on luabind::tostring implementation but I'm not very
> confident about my abilities to do concat equivalent sadly :(
>
> Thx for your answer
>
> On Wed, Mar 23, 2011 at 2:30 AM, Ryan Pavlik <[email protected]> wrote:
> >
> > __concat would be a method in the metatable, not in the table itself, so
> I think that would keep your current approach from working.  My hunch is
> that you'd need to look at the header for luabind::tostring and do something
> similar for concat.  If you do, fork Luabind on GitHub so that the
> improvement can be re-integrated.
> >
> > On Tue, Mar 22, 2011 at 11:20 PM, Teto <[email protected]> wrote:
> >>
> >> Hi there,
> >>
> >> I'm doing everything I can to ease lua side debugging and for this
> purpose, I need to override __tostring and __concat from C++.
> >>
> >> I've succeeded in overriding tostring (followed the manual + looked on
> the ml to see that if it didn't work with luabind::self, I could use
> const_self, maybe that tip could go to the online tutorial)
> >> .def( luabind::tostring(luabind::const_self) )
> >>
> >> For __concat, I do that with a wrong prototype I guess ( std::string
> CStaticBattery::concat() ):
> >>         .def( "__concat",&CStaticBattery::concat )
> >>
> >> Would the prototype : std::string CStaticBattery::concat(const
> std::string & str1,const std::string& str2 ) work ?
> >> What would be str1 and str2 ? Left and right ? like in print(
> str1..myBatteryConcat..str2) ?
> >>
> >> I will appreciate any example.
> >>
> >>
> >> Thx
> >>
> >>
> ------------------------------------------------------------------------------
> >> Enable your software for Intel(R) Active Management Technology to meet
> the
> >> growing manageability and security demands of your customers. Businesses
> >> are taking advantage of Intel(R) vPro (TM) technology - will your
> software
> >> be a part of the solution? Download the Intel(R) Manageability Checker
> >> today! http://p.sf.net/sfu/intel-dev2devmar
> >> _______________________________________________
> >> luabind-user mailing list
> >> [email protected]
> >> https://lists.sourceforge.net/lists/listinfo/luabind-user
> >>
> >
> >
> >
> > --
> > Ryan Pavlik
> > HCI Graduate Student
> > Virtual Reality Applications Center
> > Iowa State University
> >
> > [email protected]
> > http://academic.cleardefinition.com
> > Internal VRAC/HCI Site: http://tinyurl.com/rpavlik
>

------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software 
be a part of the solution? Download the Intel(R) Manageability Checker 
today! http://p.sf.net/sfu/intel-dev2devmar

_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user
concat.hpp (text/x-c++hdr, 2.4 KB)
#ifndef _BIND_CONCAT_HPP_INCLUDED
#define _BIND_CONCAT_HPP_INCLUDED

#include <luabind/luabind.hpp>
#include <luabind/operator.hpp>

namespace luabind {


#define LUABIND_BINARY_METAMETHOD(name_, op,fn) \
    namespace operators { \
\
        struct name_ \
        { \
            template<class T0, class T1, class Policies> \
            struct apply \
            { \
                static void execute(lua_State* L, T0 _0, T1 _1) \
                { \
                    detail::operator_result(L, fn(_0 , _1), (Policies*)0); \
                } \
            }; \
\
            static char const* name() \
            { \
                return "__" # name_; \
            } \
        }; \
\
    }\
    template<class T, class U> \
    detail::binary_operator< \
        operators::name_ \
      , U \
      , T \
    > \
    inline op(self_base<U>, T const&) \
    { \
        return 0; \
    } \
    \
    template<class T, class U> \
    detail::binary_operator< \
        operators::name_ \
      , T \
      , U \
    > \
    inline op(T const&, self_base<U>) \
    { \
        return 0; \
    } \
    \
    detail::binary_operator< \
        operators::name_ \
      , self_type \
      , self_type \
    > \
    inline op(self_type, self_type) \
    { \
        return 0; \
    } \
    \
    detail::binary_operator< \
        operators::name_ \
      , self_type \
      , const_self_type \
    > \
    inline op(self_type, const_self_type) \
    { \
        return 0; \
    } \
    \
    detail::binary_operator< \
        operators::name_ \
      , const_self_type \
      , self_type \
    > \
    inline op(const_self_type, self_type) \
    { \
        return 0; \
    } \
    \
    detail::binary_operator< \
        operators::name_ \
      , const_self_type \
      , const_self_type \
    > \
    inline op(const_self_type, const_self_type) \
    { \
        return 0; \
    }



    template<class T0,class T1>
    std::string onConcat(T0 const& _0,T1 const& _1)
    {
#ifdef LUABIND_NO_STRINGSTREAM
        std::strstream s;
        s << _0 << _1 << std::ends;
#else
        std::stringstream s;
        s << _0 << _1;
#endif
        return s.str();

        //return s.str();
        //return std::string("[CONCAT function called]");
    }


//concat_operator
    LUABIND_BINARY_METAMETHOD(concat,concat_operator,onConcat)

    #undef LUABIND_BINARY_METAMETHOD

}


#endif
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.