Pyd
Don Clugston
dac at nospam.com.au
Fri Jul 7 10:35:00 PDT 2006
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!().
>
>
> >>> 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
>
More information about the Digitalmars-d
mailing list