Re: Member pointers in 0.8.1

hymedia <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <002101c9c52c$8b22b3f0$a1681bd0$@ca>
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:[email protected]] 
Sent: Friday, April 24, 2009 1:23 PM
To: [email protected]
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: [email protected]
> To: [email protected]
> 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 <[email protected]>
> An: [email protected]
> 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:[email protected]] 
> Sent: Tuesday, April 14, 2009 3:07 PM
> To: [email protected]
> Subject: Re: [luabind] Member pointers in 0.8.1
> 
> Problem solved! Thanks!
> 
> On Mon, Apr 13, 2009 at 10:16 PM, Daniel Wallin <[email protected]>
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
> [email protected]
> 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
> [email protected]
> 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
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/luabind-user

  _____  

Share your photos with Windows Live Photos – Free. Try it
<http://clk.atdmt.com/UKM/go/134665338/direct/01/>  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
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user
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.