Pyd
Kirk McDonald
kirklin.mcdonald at gmail.com
Fri Jul 7 11:10:11 PDT 2006
Don Clugston wrote:
> Kirk McDonald wrote:
>
>> I've just added some nifty things to Pyd:
>>
>> [testdll.d]
>> extern (C)
>> export void inittestdll() {
>> module_init("testdll");
>>
>> def!("foo", foo);
>> // Python does not support function overloading. This allows
>> // us to wrap an overloading function under a different name.
>> def!("foo2", foo, 1, void function(int));
>> // Default argument support is now automatic.
>> def!("baz", baz);
>> // Functions and delegates can be returned into Python. (Stay
>> // tuned for the reverse operation of converting a Python
>> // callable into a function/delegate.)
>> def!("func_test", func_test);
>>
>> wrapped_class!("Foo", Foo) f;
>> // opAdd is wrapped automatically
>> f.init!(ctor!(int), ctor!(int, int));
>> f.def!("foo", Foo.foo);
>> f.prop!("i", Foo.i);
>> finalize_class(f);
>> }
>
>
> I think you should swap the order of the first two arguments to most of
> these functions. The function being wrapped is more fundamental than the
> name. If you did this, you could (for example) use my newly-updated
> meta.nameof module to change the definition of def!() to:
>
> private import meta.nameof;
>
> template def(alias fn, char[] name = symbolnameof!(fn), uint MIN_ARGS =
> NumberOfArgs!(typeof(&fn)), fn_t = typeof(&fn))
> {....}
>
> so that users would write
>
> def!(baz);
> f.def!(Foo.foo);
> f.prop!(Foo.i);
>
> Equally valid if D ever gets a built-in equivalent to symbolnameof!().
>
>
I agree! Most certainly. I've just been planning on doing it whenever I
get around to requiring (and installing :-) DDL. The definition of
def!() will actually be:
template def(alias fn, char[] name = symbolnameof!(fn), fn_t =
typeof(&fn), uint MIN_ARGS = MIN_ARGS!(fn))
(I can derive MIN_ARGS automatically now, so I now view specifying it as
more anomolous than specifying fn_t.)
I think I'll make this change in the next revision, though I'm not
adding the support for symbolnameof /quite/ yet.
>
> >
>
>>
>> >>> import testdll
>> >>> f = testdll.Foo(20)
>> >>> g = testdll.Foo(30)
>> >>> h = f + g
>> >>> h.i
>> 50
>> >>> a = testdll.func_test(f)
>> >>> a()
>> Foo.foo(): i = 20
>> >>> testdll.baz()
>> i = 10
>> s = moo
>>
--
Kirk McDonald
Pyd: Wrapping Python with D
http://dsource.org/projects/pyd/wiki
More information about the Digitalmars-d
mailing list