non const reference

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

non const reference

Remy Muller-2
hi,

here's a toy example I'd like to wrap using luabind:

struct A
{
private
     A(const A&) {}
};

struct B
{
     virtual void foo(A &a)
     {
     }
};

struct B_wrap : public B, public wrap_base
{
     virtual void foo(A &a)
     {
         call<void>("foo", a);
     }

     static void default_foo(B *p, A &a)
     {
         p->B::foo(a);
     }
};

module(L)[
class<A>,
class_<B, B_wrap>("B"),
     .def("foo", &B::foo, &B_wrap::default_foo)
];

I have questions regarding this:

the compiler complains because A constructor is private

1) Is there a non-intrusive way to inform luabind that a pointer to A*
could be used instead of the reference to avoid the copy?

2) I guess a static forwarding function like:
static function void static_foo(B *b, A *a)
{
     assert(b && a);
     b->foo(*a);
}

would solve my first question, but how to make that play well with
virtual function overloading?

3) how can I tell luabind that the lifetime of this object is only
guaranteed during this function call and shouldn't be acquired by lua code?

best

remy



------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: non const reference

Remy Muller-2
no answer?

Le 08/02/2012 12:12, Remy Muller a écrit :

> hi,
>
> here's a toy example I'd like to wrap using luabind:
>
> struct A
> {
> private
>     A(const A&) {}
> };
>
> struct B
> {
>     virtual void foo(A &a)
>     {
>     }
> };
>
> struct B_wrap : public B, public wrap_base
> {
>     virtual void foo(A &a)
>     {
>         call<void>("foo", a);
>     }
>
>     static void default_foo(B *p, A &a)
>     {
>         p->B::foo(a);
>     }
> };
>
> module(L)[
> class<A>,
> class_<B, B_wrap>("B"),
>     .def("foo", &B::foo, &B_wrap::default_foo)
> ];
>
> I have questions regarding this:
>
> the compiler complains because A constructor is private
>
> 1) Is there a non-intrusive way to inform luabind that a pointer to A*
> could be used instead of the reference to avoid the copy?
>
> 2) I guess a static forwarding function like:
> static function void static_foo(B *b, A *a)
> {
>     assert(b && a);
>     b->foo(*a);
> }
>
> would solve my first question, but how to make that play well with
> virtual function overloading?
>
> 3) how can I tell luabind that the lifetime of this object is only
> guaranteed during this function call and shouldn't be acquired by lua
> code?
>
> best
>
> remy
>
>


------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: non const reference

Willi Schinmeyer
  I've been playing around a bit and using boost::reference_wrapper<A>
instead of A& makes it compile, though I did not verify it actually
works as expected.

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: non const reference

Remy Muller-2
thanks, using

call<void>("foo", boost::ref(a));

instead of

call<void>("foo", a);

makes it compile, however my virtual function are not called. I'll try
to see if it's on my end first.

Le 24/02/2012 12:44, Willi Schinmeyer a écrit :

>    I've been playing around a bit and using boost::reference_wrapper<A>
> instead of A&  makes it compile, though I did not verify it actually
> works as expected.
>
> ------------------------------------------------------------------------------
> Virtualization&  Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user