Member pointers in 0.8.1

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

Member pointers in 0.8.1

Iliya Trendafilov
Hello guys,

I tried upgrading to 8.1 today and got hit by this strange problem:
class A has a public member of type B*, when I create an instance of B
(in Lua) and try to assign it to the member (in Lua) I get the
following error:
---
No matching overload found, candidates:
void <unknown>(A&,B* const&)
---

Here's a code sample:
----
#include <luabind/luabind.hpp>
extern "C"
{
        #include <lua.h>
        #include <lualib.h>
        #include <lauxlib.h>
};


struct B {};
struct D1 : B {};
struct D2 : D1 {};
struct A { B* b; };


int main(int argc, char* argv[])
{
        using namespace luabind;

        lua_State* l= lua_open();

        if (l)
        {
                luaL_openlibs(l);
                open(l);
                module(l)
                        [
                                class_<A>("A").def(constructor<>()).def_readwrite("b", &A::b),
                                class_<B>("B").def(constructor<>())
                        ];

                int status = luaL_dostring(l, "a = A(); a.b = B();");
                if (status != 0)
                {
                        const char* s = lua_tostring(l, 1);
                        printf("%s\n", s);
                }

                lua_close(l);
                l= NULL;
        }
}
----

Tried with both static library and DLL build of luabind with VC8 SP1
(VC2005), as well as shared libraries build on Linux (gcc4.3.2), same
story everywhere. This used to work on 0.7.1. I checked the changes
since 0.7.1 but didn't find anything related.

Thanks,
Ilia

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Member pointers in 0.8.1

James Porter-2
Ilia Trendafilov wrote:
> Hello guys,
>
> I tried upgrading to 8.1 today and got hit by this strange problem:
> class A has a public member of type B*, when I create an instance of B
> (in Lua) and try to assign it to the member (in Lua) I get the
> following error:
> ---
> No matching overload found, candidates:
> void <unknown>(A&,B* const&)

Your code works for me in Luabind 0.8.1 / Lua 5.1.4 / MSVC8 SP1 with no
problems whatsoever. Is your version of Lua up to date, and did you
compile Luabind via bjam?

- Jim


------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Member pointers in 0.8.1

Iliya Trendafilov
James Porter wrote:
> Your code works for me in Luabind 0.8.1 / Lua 5.1.4 / MSVC8 SP1 with no
> problems whatsoever. Is your version of Lua up to date, and did you
> compile Luabind via bjam?

Lua wasn't up to date, updated it to 5.1.4, recompiled everything,
still same issue. I built luabind by dropping the .cpps in visual
studio project, according to the INSTALL file that should be ok (and
it was ok for 0.7.1). Though on Linux, I did build luabind via bjam,
Lua is also up to date, and the problem is still there.

Since you can run the code, it seems that I'm doing something wrong,
but I don't have a clue what it might be. Not sure if that's relevant,
boost version is 1.37 on Windows and 1.38 on Linux, built by bjam on
both OSes.

Ilia

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Member pointers in 0.8.1

Daniel Wallin
Ilia Trendafilov wrote:
> James Porter wrote:
>> Your code works for me in Luabind 0.8.1 / Lua 5.1.4 / MSVC8 SP1 with no
>> problems whatsoever. Is your version of Lua up to date, and did you
>> compile Luabind via bjam?

Really? That's weird. It fails for me on GCC 4.3.2 as well.

> Since you can run the code, it seems that I'm doing something wrong,
> but I don't have a clue what it might be. Not sure if that's relevant,
> boost version is 1.37 on Windows and 1.38 on Linux, built by bjam on
> both OSes.

Can you try this patch, it should solve the problem:

diff --git a/luabind/class.hpp b/luabind/class.hpp
index a7dddf3..f982c23 100644
--- a/luabind/class.hpp
+++ b/luabind/class.hpp
@@ -858,6 +858,15 @@ namespace luabind
             >
         {};

+        template <class T>
+        struct reference_arg
+          : mpl::if_<
+                mpl::or_<boost::is_pointer<T>, is_primitive<T> >
+              , T
+              , typename boost::add_reference<T const>::type
+            >
+        {};
+
         template <class T, class Policies>
         struct inject_dependency_policy
           : mpl::if_<
@@ -934,7 +943,8 @@ namespace luabind
                 return make_function(
                     L
                   , access_member_ptr<T, D>(mem_ptr)
-                  , mpl::vector3<void, Class&, D const&>()
+                  , mpl::vector3<
+                        void, Class&, typename reference_arg<D>::type>()
                   , set_policies
                 );
             }


--
Daniel Wallin
BoostPro Computing
http://www.boostpro.com

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Member pointers in 0.8.1

Iliya Trendafilov
Problem solved! Thanks!

On Mon, Apr 13, 2009 at 10:16 PM, Daniel Wallin <[hidden email]> wrote:

> Ilia Trendafilov wrote:
>> James Porter wrote:
>>> Your code works for me in Luabind 0.8.1 / Lua 5.1.4 / MSVC8 SP1 with no
>>> problems whatsoever. Is your version of Lua up to date, and did you
>>> compile Luabind via bjam?
>
> Really? That's weird. It fails for me on GCC 4.3.2 as well.
>
>> Since you can run the code, it seems that I'm doing something wrong,
>> but I don't have a clue what it might be. Not sure if that's relevant,
>> boost version is 1.37 on Windows and 1.38 on Linux, built by bjam on
>> both OSes.
>
> Can you try this patch, it should solve the problem:
> ...
> Daniel Wallin
> BoostPro Computing
> http://www.boostpro.com

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Member pointers in 0.8.1

hymedia
Greetings,

This might be a no can do but you wizards out there might have an hocus
pocus workarounds...

Let say the basic function is define like this:

.def("GetObject", (Object*(Manager::*)(Name &)) &Manager::GetObjectByName)

All good, the Manger return an Object, but many classes derived from Object
in my C++ and my Luabind Modules follow the same structure. In c++ you can
statically cast to the desired type... Is there a way to static cast a
Luabind return value within a Lua script?

Something like:

local l_camera = (Camera*) Manager:GetObject(Name("Camera"));


This would work But it is not really sexy...

.def("GetActor", (Actor*(Manager::*)(Name &)) &Manager::GetObjectByName)
.def("GetCamera", (Camera*(Manager::*)(Name &)) &Manager::GetObjectByName)

thx

-----Original Message-----
From: Ilia Trendafilov [mailto:[hidden email]]
Sent: Tuesday, April 14, 2009 3:07 PM
To: [hidden email]
Subject: Re: [luabind] Member pointers in 0.8.1

Problem solved! Thanks!

On Mon, Apr 13, 2009 at 10:16 PM, Daniel Wallin <[hidden email]> wrote:

> Ilia Trendafilov wrote:
>> James Porter wrote:
>>> Your code works for me in Luabind 0.8.1 / Lua 5.1.4 / MSVC8 SP1 with no
>>> problems whatsoever. Is your version of Lua up to date, and did you
>>> compile Luabind via bjam?
>
> Really? That's weird. It fails for me on GCC 4.3.2 as well.
>
>> Since you can run the code, it seems that I'm doing something wrong,
>> but I don't have a clue what it might be. Not sure if that's relevant,
>> boost version is 1.37 on Windows and 1.38 on Linux, built by bjam on
>> both OSes.
>
> Can you try this patch, it should solve the problem:
> ...
> Daniel Wallin
> BoostPro Computing
> http://www.boostpro.com

----------------------------------------------------------------------------
--
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------
Crystal Reports &#45; New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty&#45;free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Member pointers in 0.8.1

Tony Kostanjsek

I'd be interested in a solution for this as well. What we did as a workaorund was to add cast functions to the lua bindings for the derived classes, so you have to know that (in Lua) you receive a Object* and then convert like this: local actor = Actor.cast(myobject).
It does feel wrong to introduce casts like this to a dynamic language, but at least it works. Ultimately, we rewrote part of our project specifically because of these problems and reimplemented some of the classes in pure lua.
I really wish luabind was more intelligent and forgiving when it comes to (smart)pointer casts and general usage.
Best,
Tony


----- Ursprüngliche Mail ----
Von: hymedia <[hidden email]>
An: [hidden email]
Gesendet: Freitag, den 24. April 2009, 19:04:53 Uhr
Betreff: Re: [luabind] Member pointers in 0.8.1

Greetings,

This might be a no can do but you wizards out there might have an hocus
pocus workarounds...

Let say the basic function is define like this:

.def("GetObject", (Object*(Manager::*)(Name &)) &Manager::GetObjectByName)

All good, the Manger return an Object, but many classes derived from Object
in my C++ and my Luabind Modules follow the same structure. In c++ you can
statically cast to the desired type... Is there a way to static cast a
Luabind return value within a Lua script?

Something like:

local l_camera = (Camera*) Manager:GetObject(Name("Camera"));


This would work But it is not really sexy...

.def("GetActor", (Actor*(Manager::*)(Name &)) &Manager::GetObjectByName)
.def("GetCamera", (Camera*(Manager::*)(Name &)) &Manager::GetObjectByName)

thx

-----Original Message-----
From: Ilia Trendafilov [mailto:[hidden email]]
Sent: Tuesday, April 14, 2009 3:07 PM
To: [hidden email]
Subject: Re: [luabind] Member pointers in 0.8.1

Problem solved! Thanks!

On Mon, Apr 13, 2009 at 10:16 PM, Daniel Wallin <[hidden email]> wrote:

> Ilia Trendafilov wrote:
>> James Porter wrote:
>>> Your code works for me in Luabind 0.8.1 / Lua 5.1.4 / MSVC8 SP1 with no
>>> problems whatsoever. Is your version of Lua up to date, and did you
>>> compile Luabind via bjam?
>
> Really? That's weird. It fails for me on GCC 4.3.2 as well.
>
>> Since you can run the code, it seems that I'm doing something wrong,
>> but I don't have a clue what it might be. Not sure if that's relevant,
>> boost version is 1.37 on Windows and 1.38 on Linux, built by bjam on
>> both OSes.
>
> Can you try this patch, it should solve the problem:
> ...
> Daniel Wallin
> BoostPro Computing
> http://www.boostpro.com

----------------------------------------------------------------------------
--
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user



     

------------------------------------------------------------------------------
Crystal Reports &#45; New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty&#45;free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Member pointers in 0.8.1

Marcus Speight-2
Define function to accept the raw state

.def("GetObject", (luabind::object(Manager::*)(Name&, lua_State*)) &Manager::GetObjectByName, raw(_2))

In you base object class add a virtual function called asLua

class Object
{
    ...
    virtual luabind::object asLua(lua_State *L) = 0;
};

The new GetObjectByName function calls the one you already have then calls the new asLua function

luabind::object Manager::GetObjectByName(Name& n, lua_State *L)
{
    Object *obj = GetObjectByName(n);
    return obj->asLua(L);
}

In derived classes override the asLua function

class Camera
{
    ...
    virtual luabind::object asLua(lua_State *L) { return luabind::object(this, L); }
};

The result is the function returns a derived type.

local l_camera = Manager::GetObject(Name("Camera"));

l_camera is of type Camera.

> Date: Fri, 24 Apr 2009 17:19:28 +0000
> From: [hidden email]
> To: [hidden email]
> Subject: Re: [luabind] Member pointers in 0.8.1
>
>
> I'd be interested in a solution for this as well. What we did as a workaorund was to add cast functions to the lua bindings for the derived classes, so you have to know that (in Lua) you receive a Object* and then convert like this: local actor = Actor.cast(myobject).
> It does feel wrong to introduce casts like this to a dynamic language, but at least it works. Ultimately, we rewrote part of our project specifically because of these problems and reimplemented some of the classes in pure lua.
> I really wish luabind was more intelligent and forgiving when it comes to (smart)pointer casts and general usage.
> Best,
> Tony
>
>
> ----- Ursprüngliche Mail ----
> Von: hymedia <[hidden email]>
> An: [hidden email]
> Gesendet: Freitag, den 24. April 2009, 19:04:53 Uhr
> Betreff: Re: [luabind] Member pointers in 0.8.1
>
> Greetings,
>
> This might be a no can do but you wizards out there might have an hocus
> pocus workarounds...
>
> Let say the basic function is define like this:
>
> .def("GetObject", (Object*(Manager::*)(Name &)) &Manager::GetObjectByName)
>
> All good, the Manger return an Object, but many classes derived from Object
> in my C++ and my Luabind Modules follow the same structure. In c++ you can
> statically cast to the desired type... Is there a way to static cast a
> Luabind return value within a Lua script?
>
> Something like:
>
> local l_camera = (Camera*) Manager:GetObject(Name("Camera"));
>
>
> This would work But it is not really sexy...
>
> .def("GetActor", (Actor*(Manager::*)(Name &)) &Manager::GetObjectByName)
> .def("GetCamera", (Camera*(Manager::*)(Name &)) &Manager::GetObjectByName)
>
> thx
>
> -----Original Message-----
> From: Ilia Trendafilov [mailto:[hidden email]]
> Sent: Tuesday, April 14, 2009 3:07 PM
> To: [hidden email]
> Subject: Re: [luabind] Member pointers in 0.8.1
>
> Problem solved! Thanks!
>
> On Mon, Apr 13, 2009 at 10:16 PM, Daniel Wallin <[hidden email]> wrote:
> > Ilia Trendafilov wrote:
> >> James Porter wrote:
> >>> Your code works for me in Luabind 0.8.1 / Lua 5.1.4 / MSVC8 SP1 with no
> >>> problems whatsoever. Is your version of Lua up to date, and did you
> >>> compile Luabind via bjam?
> >
> > Really? That's weird. It fails for me on GCC 4.3.2 as well.
> >
> >> Since you can run the code, it seems that I'm doing something wrong,
> >> but I don't have a clue what it might be. Not sure if that's relevant,
> >> boost version is 1.37 on Windows and 1.38 on Linux, built by bjam on
> >> both OSes.
> >
> > Can you try this patch, it should solve the problem:
> > ...
> > Daniel Wallin
> > BoostPro Computing
> > http://www.boostpro.com
>
> ----------------------------------------------------------------------------
> --
> This SF.net email is sponsored by:
> High Quality Requirements in a Collaborative Environment.
> Download a free trial of Rational Requirements Composer Now!
> http://p.sf.net/sfu/www-ibm-com
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
>
> ------------------------------------------------------------------------------
> Crystal Reports - New Free Runtime and 30 Day Trial
> Check out the new simplified licensign option that enables unlimited
> royalty-free distribution of the report engine for externally facing
> server and web deployment.
> http://p.sf.net/sfu/businessobjects
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
>
>
>
>
> ------------------------------------------------------------------------------
> Crystal Reports &#45; New Free Runtime and 30 Day Trial
> Check out the new simplified licensign option that enables unlimited
> royalty&#45;free distribution of the report engine for externally facing
> server and web deployment.
> http://p.sf.net/sfu/businessobjects
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user


Share your photos with Windows Live Photos – Free. Try it Now!
------------------------------------------------------------------------------
Crystal Reports &#45; New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty&#45;free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Casting to derived type (was: Member pointers in 0.8.1)

Daniel Wallin
In reply to this post by hymedia
> I'd be interested in a solution for this as well. What we did as a
> workaorund was to add cast functions to the lua bindings for the derived
> classes, so you have to know that (in Lua) you receive a Object* and
> then convert like this: local actor = Actor.cast(myobject).
> It does feel wrong to introduce casts like this to a dynamic
> language,
> but at least it works. Ultimately, we rewrote part of our project
> specifically because of these problems and reimplemented some of the
> classes in pure lua.
> I really wish luabind was more intelligent and forgiving when it
> comes
> to (smart)pointer casts and general usage.

FWIW, the next release is much better in this regard. It will perform
automatic down-casting then a reference to a polymorphic type is passed
to Lua.

Unfortunately I don't have much time to work on luabind right now, but
hopefully I'll be ready to release the next version in a couple of months.

--
Daniel Wallin
BoostPro Computing
http://www.boostpro.com

------------------------------------------------------------------------------
Crystal Reports &#45; New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty&#45;free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Member pointers in 0.8.1

Tony Kostanjsek
In reply to this post by Marcus Speight-2
Marcus,
awesome! That should go into the official docs for slow people like me. I remember vaguely thinking about a similar solution, but back then I think we didn't want to include lua/luabind in all of the classes that needed to be bound, but that requirement changed over time. Also, I didn't get the raw_ policy at all :)
I assume, this would work just as fine for returning shared_ptr using shared_from_this ?

Daniel,
thanks for the heads up on the downcasts! 

best,
Tony



Von: Marcus Speight <[hidden email]>
An: [hidden email]
Gesendet: Freitag, den 24. April 2009, 19:22:31 Uhr
Betreff: Re: [luabind] Member pointers in 0.8.1

Define function to accept the raw state

.def("GetObject", (luabind::object(Manager::*)(Name&, lua_State*)) &Manager::GetObjectByName, raw(_2))

In you base object class add a virtual function called asLua

class Object
{
    ...
    virtual luabind::object asLua(lua_State *L) = 0;
};

The new GetObjectByName function calls the one you already have then calls the new asLua function

luabind::object Manager::GetObjectByName(Name& n, lua_State *L)
{
    Object *obj = GetObjectByName(n);
    return obj->asLua(L);
}

In derived classes override the asLua function

class Camera
{
    ...
    virtual luabind::object asLua(lua_State *L) { return luabind::object(this, L); }
};

The result is the function returns a derived type.

local l_camera = Manager::GetObject(Name("Camera"));

l_camera is of type Camera.

> Date: Fri, 24 Apr 2009 17:19:28 +0000
> From: [hidden email]
> To: [hidden email]
> Subject: Re: [luabind] Member pointers in 0.8.1
>
>
> I'd be interested in a solution for this as well. What we did as a workaorund was to add cast functions to the lua bindings for the derived classes, so you have to know that (in Lua) you receive a Object* and then convert like this: local actor = Actor.cast(myobject).
> It does feel wrong to introduce casts like this to a dynamic language, but at least it works. Ultimately, we rewrote part of our project specifically because of these problems and reimplemented some of the classes in pure lua.
> I really wish luabind was more intelligent and forgiving when it comes to (smart)pointer casts and general usage.
> Best,
> Tony
>
>
> ----- Ursprüngliche Mail ----
> Von: hymedia <[hidden email]>
> An: [hidden email]
> Gesendet: Freitag, den 24. April 2009, 19:04:53 Uhr
> Betreff: Re: [luabind] Member pointers in 0.8.1
>
> Greetings,
>
> This might be a no can do but you wizards out there might have an hocus
> pocus workarounds...
>
> Let say the basic function is define like this:
>
> .def("GetObject", (Object*(Manager::*)(Name &)) &Manager::GetObjectByName)
>
> All good, the Manger return an Object, but many classes derived from Object
> in my C++ and my Luabind Modules follow the same structure. In c++ you can
> statically cast to the desired type... Is there a way to static cast a
> Luabind return value within a Lua script?
>
> Something like:
>
> local l_camera = (Camera*) Manager:GetObject(Name("Camera"));
>
>
> This would work But it is not really sexy...
>
> .def("GetActor", (Actor*(Manager::*)(Name &)) &Manager::GetObjectByName)
> .def("GetCamera", (Camera*(Manager::*)(Name &)) &Manager::GetObjectByName)
>
> thx
>
> -----Original Message-----
> From: Ilia Trendafilov [mailto:[hidden email]]
> Sent: Tuesday, April 14, 2009 3:07 PM
> To: [hidden email]
> Subject: Re: [luabind] Member pointers in 0.8.1
>
> Problem solved! Thanks!
>
> On Mon, Apr 13, 2009 at 10:16 PM, Daniel Wallin <[hidden email]> wrote:
> > Ilia Trendafilov wrote:
> >> James Porter wrote:
> >>> Your code works for me in Luabind 0.8.1 / Lua 5.1.4 / MSVC8 SP1 with no
> >>> problems whatsoever. Is your version of Lua up to date, and did you
> >>> compile Luabind via bjam?
> >
> > Really? That's weird. It fails for me on GCC 4.3.2 as well.
> >
> >> Since you can run the code, it seems that I'm doing something wrong,
> >> but I don't have a clue what it might be. Not sure if that's relevant,
> >> boost version is 1.37 on Windows and 1.38 on Linux, built by bjam on
> >> both OSes.
> >
> > Can you try this patch, it should solve the problem:
> > ...
> > Daniel Wallin
> > BoostPro Computing
> > http://www.boostpro.com
>
> ----------------------------------------------------------------------------
> --
> This SF.net email is sponsored by:
> High Quality Requirements in a Collaborative Environment.
> Download a free trial of Rational Requirements Composer Now!
> http://p.sf.net/sfu/www-ibm-com
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
>
> ------------------------------------------------------------------------------
> Crystal Reports - New Free Runtime and 30 Day Trial
> Check out the new simplified licensign option that enables unlimited
> royalty-free distribution of the report engine for externally facing
> server and web deployment.
> http://p.sf.net/sfu/businessobjects
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
>
>
>
>
> ------------------------------------------------------------------------------
> Crystal Reports &#45; New Free Runtime and 30 Day Trial
> Check out the new simplified licensign option that enables unlimited
> royalty&#45;free distribution of the report engine for externally facing
> server and web deployment.
> http://p.sf.net/sfu/businessobjects
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user


Share your photos with Windows Live Photos – Free. Try it Now!


------------------------------------------------------------------------------
Crystal Reports &#45; New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty&#45;free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Member pointers in 0.8.1

hymedia
In reply to this post by Marcus Speight-2

Thx for your post Marcus,

 

When trying to compile this line:

 

.def("GetObject", (luabind::object(Manager::*)(Name&, lua_State*)) &Manager::GetObjectByName, raw(_2))

 

I m getting this:

 

Error      1              error C2664: 'luabind::detail::raw_converter::apply' : cannot convert parameter 2 from 'luabind::detail::by_reference<T>' to 'luabind::detail::by_pointer<T>'

Error      2              error C2664: 'luabind::detail::raw_converter::converter_postcall' : cannot convert parameter 2 from 'luabind::detail::by_reference<T>' to 'luabind::detail::by_pointer<T>'

 

Note: Im still using version, 0.8

 

Hum?

 

From: Marcus Speight [mailto:[hidden email]]
Sent: Friday, April 24, 2009 1:23 PM
To: [hidden email]
Subject: Re: [luabind] Member pointers in 0.8.1

 

Define function to accept the raw state

.def("GetObject", (luabind::object(Manager::*)(Name&, lua_State*)) &Manager::GetObjectByName, raw(_2))

In you base object class add a virtual function called asLua

class Object
{
    ...
    virtual luabind::object asLua(lua_State *L) = 0;
};

The new GetObjectByName function calls the one you already have then calls the new asLua function

luabind::object Manager::GetObjectByName(Name& n, lua_State *L)
{
    Object *obj = GetObjectByName(n);
    return obj->asLua(L);
}

In derived classes override the asLua function

class Camera
{
    ...
    virtual luabind::object asLua(lua_State *L) { return luabind::object(this, L); }
};

The result is the function returns a derived type.

local l_camera = Manager::GetObject(Name("Camera"));

l_camera is of type Camera.

> Date: Fri, 24 Apr 2009 17:19:28 +0000
> From: [hidden email]
> To: [hidden email]
> Subject: Re: [luabind] Member pointers in 0.8.1
>
>
> I'd be interested in a solution for this as well. What we did as a workaorund was to add cast functions to the lua bindings for the derived classes, so you have to know that (in Lua) you receive a Object* and then convert like this: local actor = Actor.cast(myobject).
> It does feel wrong to introduce casts like this to a dynamic language, but at least it works. Ultimately, we rewrote part of our project specifically because of these problems and reimplemented some of the classes in pure lua.
> I really wish luabind was more intelligent and forgiving when it comes to (smart)pointer casts and general usage.
> Best,
> Tony
>
>
> ----- Ursprüngliche Mail ----
> Von: hymedia <[hidden email]>
> An: [hidden email]
> Gesendet: Freitag, den 24. April 2009, 19:04:53 Uhr
> Betreff: Re: [luabind] Member pointers in 0.8.1
>
> Greetings,
>
> This might be a no can do but you wizards out there might have an hocus
> pocus workarounds...
>
> Let say the basic function is define like this:
>
> .def("GetObject", (Object*(Manager::*)(Name &)) &Manager::GetObjectByName)
>
> All good, the Manger return an Object, but many classes derived from Object
> in my C++ and my Luabind Modules follow the same structure. In c++ you can
> statically cast to the desired type... Is there a way to static cast a
> Luabind return value within a Lua script?
>
> Something like:
>
> local l_camera = (Camera*) Manager:GetObject(Name("Camera"));
>
>
> This would work But it is not really sexy...
>
> .def("GetActor", (Actor*(Manager::*)(Name &)) &Manager::GetObjectByName)
> .def("GetCamera", (Camera*(Manager::*)(Name &)) &Manager::GetObjectByName)
>
> thx
>
> -----Original Message-----
> From: Ilia Trendafilov [mailto:[hidden email]]
> Sent: Tuesday, April 14, 2009 3:07 PM
> To: [hidden email]
> Subject: Re: [luabind] Member pointers in 0.8.1
>
> Problem solved! Thanks!
>
> On Mon, Apr 13, 2009 at 10:16 PM, Daniel Wallin <[hidden email]> wrote:
> > Ilia Trendafilov wrote:
> >> James Porter wrote:
> >>> Your code works for me in Luabind 0.8.1 / Lua 5.1.4 / MSVC8 SP1 with no
> >>> problems whatsoever. Is your version of Lua up to date, and did you
> >>> compile Luabind via bjam?
> >
> > Really? That's weird. It fails for me on GCC 4.3.2 as well.
> >
> >> Since you can run the code, it seems that I'm doing something wrong,
> >> but I don't have a clue what it might be. Not sure if that's relevant,
> >> boost version is 1.37 on Windows and 1.38 on Linux, built by bjam on
> >> both OSes.
> >
> > Can you try this patch, it should solve the problem:
> > ...
> > Daniel Wallin
> > BoostPro Computing
> > http://www.boostpro.com
>
> ----------------------------------------------------------------------------
> --
> This SF.net email is sponsored by:
> High Quality Requirements in a Collaborative Environment.
> Download a free trial of Rational Requirements Composer Now!
> http://p.sf.net/sfu/www-ibm-com
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
>
> ------------------------------------------------------------------------------
> Crystal Reports - New Free Runtime and 30 Day Trial
> Check out the new simplified licensign option that enables unlimited
> royalty-free distribution of the report engine for externally facing
> server and web deployment.
> http://p.sf.net/sfu/businessobjects
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
>
>
>
>
> ------------------------------------------------------------------------------
> Crystal Reports &#45; New Free Runtime and 30 Day Trial
> Check out the new simplified licensign option that enables unlimited
> royalty&#45;free distribution of the report engine for externally facing
> server and web deployment.
> http://p.sf.net/sfu/businessobjects
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user


Share your photos with Windows Live Photos – Free. Try it Now!


------------------------------------------------------------------------------
Crystal Reports &#45; New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty&#45;free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Casting to derived type

hymedia
In reply to this post by Tony Kostanjsek
Marcus solution might work but will propagate Lua in your code and increase
compile time seriously... however, his solution was inspiring:

class LuaBind
{
        public:

...SNIP
                static object GetObjectByName(Name &in_name, const e_TypeId
&in_id);

                static lua_State *m_Lua;
};

object LuaBind::GetObjectByName(Name &in_name, const e_TypeId &in_id)
{
        Object *l_object = Manager::GetObjectByName(in_name, in_id);

        switch (in_id)
        {
                case AX6_TYPEID_ACTOR: return object(m_Lua,
(Actor*) l_object);
                case AX6_TYPEID_CAMERA: return object(m_Lua,
(Camera*) l_object);
        }
        return object();
}

def("GetObjectByName", &LuaBind::GetObjectByName)

local l_camera = GetObjectByName(Name("Camera"), TYPEID_CAMERA);

simple, but works for me!

Thx again

-----Original Message-----
From: Tony Kostanjsek [mailto:[hidden email]]
Sent: Friday, April 24, 2009 1:19 PM
To: [hidden email]
Subject: Re: [luabind] Member pointers in 0.8.1


I'd be interested in a solution for this as well. What we did as a
workaorund was to add cast functions to the lua bindings for the derived
classes, so you have to know that (in Lua) you receive a Object* and then
convert like this: local actor = Actor.cast(myobject).
It does feel wrong to introduce casts like this to a dynamic language, but
at least it works. Ultimately, we rewrote part of our project specifically
because of these problems and reimplemented some of the classes in pure lua.
I really wish luabind was more intelligent and forgiving when it comes to
(smart)pointer casts and general usage.
Best,
Tony


----- Ursprüngliche Mail ----
Von: hymedia <[hidden email]>
An: [hidden email]
Gesendet: Freitag, den 24. April 2009, 19:04:53 Uhr
Betreff: Re: [luabind] Member pointers in 0.8.1

Greetings,

This might be a no can do but you wizards out there might have an hocus
pocus workarounds...

Let say the basic function is define like this:

.def("GetObject", (Object*(Manager::*)(Name &)) &Manager::GetObjectByName)

All good, the Manger return an Object, but many classes derived from Object
in my C++ and my Luabind Modules follow the same structure. In c++ you can
statically cast to the desired type... Is there a way to static cast a
Luabind return value within a Lua script?

Something like:

local l_camera = (Camera*) Manager:GetObject(Name("Camera"));


This would work But it is not really sexy...

.def("GetActor", (Actor*(Manager::*)(Name &)) &Manager::GetObjectByName)
.def("GetCamera", (Camera*(Manager::*)(Name &)) &Manager::GetObjectByName)

thx

-----Original Message-----
From: Ilia Trendafilov [mailto:[hidden email]]
Sent: Tuesday, April 14, 2009 3:07 PM
To: [hidden email]
Subject: Re: [luabind] Member pointers in 0.8.1

Problem solved! Thanks!

On Mon, Apr 13, 2009 at 10:16 PM, Daniel Wallin <[hidden email]> wrote:

> Ilia Trendafilov wrote:
>> James Porter wrote:
>>> Your code works for me in Luabind 0.8.1 / Lua 5.1.4 / MSVC8 SP1 with no
>>> problems whatsoever. Is your version of Lua up to date, and did you
>>> compile Luabind via bjam?
>
> Really? That's weird. It fails for me on GCC 4.3.2 as well.
>
>> Since you can run the code, it seems that I'm doing something wrong,
>> but I don't have a clue what it might be. Not sure if that's relevant,
>> boost version is 1.37 on Windows and 1.38 on Linux, built by bjam on
>> both OSes.
>
> Can you try this patch, it should solve the problem:
> ...
> Daniel Wallin
> BoostPro Computing
> http://www.boostpro.com

----------------------------------------------------------------------------
--
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user


----------------------------------------------------------------------------
--
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user



     

----------------------------------------------------------------------------
--
Crystal Reports &#45; New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty&#45;free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------
Crystal Reports &#45; New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty&#45;free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Casting to derived type

Marcus Speight-2
There was a mistake in the defining of the function it should have been _raw(3) not _raw(2)

i.e.

.def("GetObject", (luabind::object(Manager::*)(Name&, lua_State*)) &Manager::GetObjectByName, raw(_3))


To not propagate Lua through all your code but have the C++ code work out the type (and not rely on the script writer)
Mix hymedia's and my code to give

class Object
{
    ...
    virtual eTypeId getTypeId() = 0;
};


luabind::object Manager::GetObjectByName(Name& n, lua_State *L)
{
    Object *obj = GetObjectByName(n);
    eTypeId typeId = obj->getTypeId();

    switch(typeId)
    {
    case AX6_TYPEID_ACTOR: return luabind::object((Actor*)obj, L);
    case AX6_TYPEID_CAMERA: return luabind::object((Camera*)obj, L);
    ...
    }
}

local l_camera = GetObjectByName(Name("Camera"));

or without virtual functions you would use RTTI

luabind::object Manager::GetObjectByName(Name& n, lua_State *L)
{
    Object *obj = GetObjectByName(n);
    const type_info& tInfo = typeid(*obj);

    if(tInfo == typeid(Actor))
        return luabind::object((Actor*)obj, L);
    else if(tInfo == typeid(Camera))
        return luabind::object((Camera*)obj, L);
    else
        return an_error;
}




> From: [hidden email]
> To: [hidden email]
> Date: Fri, 24 Apr 2009 19:33:10 -0400
> Subject: Re: [luabind] Casting to derived type
>
> Marcus solution might work but will propagate Lua in your code and increase
> compile time seriously... however, his solution was inspiring:
>
> class LuaBind
> {
> public:
>
> ...SNIP
> static object GetObjectByName(Name &in_name, const e_TypeId
> &in_id);
>
> static lua_State *m_Lua;
> };
>
> object LuaBind::GetObjectByName(Name &in_name, const e_TypeId &in_id)
> {
> Object *l_object = Manager::GetObjectByName(in_name, in_id);
>
> switch (in_id)
> {
> case AX6_TYPEID_ACTOR: return object(m_Lua,
> (Actor*) l_object);
> case AX6_TYPEID_CAMERA: return object(m_Lua,
> (Camera*) l_object);
> }
> return object();
> }
>
> def("GetObjectByName", &LuaBind::GetObjectByName)
>
> local l_camera = GetObjectByName(Name("Camera"), TYPEID_CAMERA);
>
> simple, but works for me!
>
> Thx again


" Upgrade to Internet Explorer 8 Optimised for MSN. " Download Now
------------------------------------------------------------------------------
Crystal Reports &#45; New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty&#45;free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user