Re: [Implementation] Calling wrapped functions, converters, policies

David Abrahams <[email protected]>
Newsgroups gmane.comp.lib.boost.langbinding
Message-ID <[email protected]>
Daniel Wallin <[email protected]> writes:

> David Abrahams wrote:
>
>> Daniel Wallin <[email protected]> writes:
>> 
>>>David Abrahams wrote:
>>>
>>>>Daniel Wallin <[email protected]> writes:
>>>>
>>>>
>>>>>David Abrahams wrote:
>>>>>
>>>>>
>>>>>>I would be strongly inclined to say that unless you _explicitly_ say
>>>>>>otherwise, each C++ argument comes from the Py/Lu argument in the
>>>>>>same position.  Your example uses implicit argument shifting, which
>>>>>> makes me  nervous.  
>>>>>
>>>>>Why does it make you nervous? Is there any potential danger in doing
>>>>>this that I'm missing?
>>>>
>>>>Well, suppose in a 5-arg function you write:
>>>>      getC++.arg(2).from_Python_arg(1)
>> This is a policy which maps Python argument 1 to C++ argument 2
>> 
>>>>[Sorry, can't stop inventing syntax ;-)]
>>>>The question is, what happens to to the other 4 arguments?  It's far
>>>>from obvious to me.  Now suppose you add
>>>>      , getC++.arg(1).from_Python_arg(4)
>>>>Now it's even less obvious.
>> This is an additional policy that maps Python argument 4 to C++
>> argument 1
>
> OK. So we would end up with:
>
>    get(..., mpl::int_<2>)
>    {
>       return get(..., mpl::int_<1>());
>    }
>
>    get(..., mpl::int_<1>)
>    {
>       return get(..., mpl::int_<4>());
>    }
>
>    template<int N>
>    get(..., mpl::int_<N> n)
>    {
>       return whatever_native_thing_we_have(n);
>    }

Which does no implicit shifting AFAICT.

> This has nothing to do with (implicit) shifting though

what else have we just been discussing?

> but rather with argument_package. 

That's an implementation detail.  My concern is about user interface.

> So in this case, nothing would happen to the other arguments. I'm
> missing what's not obvious here, sorry. What I considered before was
> just converters that could merge several (consecutive) Python/Lua
> arguments into one C++ argument,

Oh, that's a restriction you hadn't explained.  They only _merge
consecutive_ args!  That might be reasonable.

Nesting of policies, however, would only work if they were properly
sorted.  I think some other mechanism is needed for the siblings to
communicate positional information up to a parent policy.

> in which case implicit shifting would be great. 

Yeah.  Ironically (?), I think needing to explode a single Python
argument to two C++ args is far more likely:

    void f(int count, char const** strings);

    >>> f(['foo', 'bar', 'baz'])


Did you happen to notice the discussion of runtime-polymorphic,
unified-syntax wrapping on the C++-sig?


-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com



-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
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.