Re: [luabind] help with pure_out_value
Brought to you by:
arvidn,
daniel_wallin
From: Hermann F. <her...@gm...> - 2005-07-30 15:57:36
|
Hi! The problem is that pure_out_value is broken. This is because the `m_arity´ member of the `overload_rep´ structure, which specifies the number of parameters of the function overload, is not calculated correctly - it is always short by 1. Therefore the signature matching algorithm will refuse to find your method. But that is not the biggest problem - the reason for why it is not calculated correctly is that for methods the association between parameter number and the conversion_policy that is used for a specific element of the m_params array in `overload_rep´ is off by one, since it "forgets" about the implied "self"-parameter. That means the parameters the `pure_out_value´ policy is applied to, will always be the ones next to the one you actually specified. However, if you try to work around the problem by specifying the ones next to the parameter you mean, your program will not compile, since the compiler's type checks will be performed with the parameters you actually specified. The fix for this all is quite simple, though. All you need to do is to make the following small changes in the file luabind/detail/overload_rep.hpp: * You need to change the definition of `LUABIND_POLICY_DECL´ so that instead of "...find_conversion_policy<n + 1, Policies>..." it says "...find_conversion_policy<n + 2, Policies>..." (the dots are not actually part of the definition). This will make the pure_out_value policy work with class member functions but break free functions and operator overloading (because they really need to have at n + 1), so you need to make the following additional change: * Before the last definition of overload_rep in the file, which is the one for free functions, add an "#undef LUABIND_POLICY_DECL" and #define it to the original value (with find_conversion_policy<n + 1, Policies> in it). That should make pure_out_value policy work - at least it did for me, and I've been using it quite extensively with both methods and free functions in a project at work. Instead of "#undef" and a new "#define" you can also just add another #define for LUABIND_POLICY_DECL with a different name for free functions and change LUABIND_POLICY_DECL to that name in the last paragraph, of course. Hope I could be of some help, Hermann Clarke, Trevor wrote: > I'm using the latest CVS w/ latest boost. I'm trying to wrap some > existing C++ classes and I have something that is essentially this. > > > > class foo > > { > > public: > > bool bar(std::string &a) > > { > > a = "foobie"; > > return true; > > } > > }; > > > > I'm wrapping like this: > > > > class_<foo>("foo").def(constructor<>()).def("bar", &foo::bar, > discard_result + pure_out_value(_2)) > > > > The problem is, pure_out_value doesn't seem to be working as I have to > call in lua like this: > > > > f = foo() > > nm = f:bar("") > > > > Am I doing something wrong? Is this a known bug in CVS (as of July 28, > 2005)? > > > > ------------------------------ > > Trevor R.H. Clarke > > tclarke at ball com <mailto:tc...@ba...> > > Ball Aerospace & Technologies Corp > > > |