Re: Re: new round
Alexander Nasonov <[email protected]>
| Newsgroups | gmane.comp.lib.boost.langbinding |
|---|---|
| Message-ID | <[email protected]> |
Daniel Wallin wrote:
> There are at least two cases where it won't work:
>
> struct A { void f(); }
> struct B : A {};
>
> class_<B>("B") [
> def("f", &B::f) // signature is void(A::*)() but A isn't
> // wrapped.
> ]
>
> and the most trivial..
>
> class_<A>("A") [
> def(constructor<>()) // Error, we need to explicitly mention
> ] // the wrapped type for every constructor
>
> There might be a lot of more cases where it is highly desirable to know
> the wrapped type at compile time. There is, IMO, no gain in separating
> the def() call from class_.
I give up. However, I believe there is a way to convert to non-wrapped base
using try-throw-catch:
template<class Derived>
void throw_(void* p)
{
throw static_cast<Derived*>(p);
}
template<class Base>
void* catch_and_convert(void (*throw_func)(void*), void* arg)
{
try
{
throw_func(arg);
}
catch(Base* result)
{
return result;
}
catch(...)
{
return 0;
}
}
Then your example
class_<B>("B") [
def("f", &B::f) // signature is void(A::*)() but A isn't
// wrapped.
]
could be implemented using throw_<B> and catch_and_convert<A>. Object on the
left to [] holds a pointer to throw<B>, object inside [] has a collection
of def each holding a pointer to catch_and_convert<XXX> (only one def with
XXX=A in this case). You might loop through defs with unwrapped XXX and
call catch_and_convert<XXX> until you found a conversion.
Of course this is not perfect solution. It might be used as a fallback
solution, though. Probably, we could use it to relax some langbinding
rules.
>> My model might look too minimalistic to you. All I need is a way to
>> prepare arguments for a call and then make a call.
>
> Well, it looks somewhat like the system we have settled on for
> langbinding. I do think there might be things you have overlooked, and
> again urge you to look at the work done before. There are reasons
> behind (most of ;)) the design choices made in libraries like BPL and
> luabind.
I can't find langbinding sources :( I've started my own development only
because I'm not able to use langbinding.
>
> Daniel Wallin
>
--
Alexander Nasonov
Independent Developer and Consultant
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click