Pyd: Stackthreads and returning arrays from D
Kirk McDonald
kirklin.mcdonald at gmail.com
Wed Jun 27 03:29:32 PDT 2007
Simen Haugen wrote:
> Ok, I just cannot get it to work..
> Look at this simple example:
>
> import pyd.pyd;
>
>
> class Item {
> }
>
>
> class Container {
> private:
> Item[] _items;
>
> public:
> Item[] items() {
> return _items;
> }
>
> void items(Item[] items) {
> _items = items;
> }
> }
>
>
> extern(C) void PydMain() {
> module_init();
>
> wrap_class!(Item);
>
> wrap_class!(
> Container,
> Property!(Container.items)
> );
> }
>
> When trying to compile this I get an error "expected to return a value of
> type Item[]" for the Container.items property:
>
[snip] (Man, Pyd has verbose compilation output...)
> C:\Python24\lib\site-packages\celerid\infrastructure\pyd\make_object.d(228):
> fun
> ction pyd.make_object.d_type!(Item[]).d_type expected to return a value of
> type
> Item[]
> C:\Python24\lib\site-packages\celerid\infrastructure\pyd\make_object.d(289):
> tem
> plate instance pyd.make_object.d_type!(Item[]) error instantiating
> C:\Python24\lib\site-packages\celerid\infrastructure\pyd\func_wrap.d(274):
> templ
> ate instance pyd.func_wrap.PydWrappedFunc.fn!(Item[]) error instantiating
> C:\Python24\lib\site-packages\celerid\infrastructure\pyd\func_wrap.d(264):
> templ
> ate instance pyd.func_wrap._pycallable_asdgT!(Item[] delegate(())) error
> instant
> iating
> error: command 'c:\d\dmd\bin\dmd.exe' failed with exit status 1
>
Careful reading of the type conversion docs
http://pyd.dsource.org/conversion.html
will reveal that, while Pyd is capable of converting D arrays to Python
lists, it is currently unable to perform the reverse operation (with the
exception of char arrays, of course). This is obviously stupid, and
getting Pyd's handling of arrays right has been bumped up on my priority
list. (I'll probably set it up so that any Python iterable whose
elements can be converted to the proper type can be converted to a D array.)
>
> When I used stackthreads I had no problem returning array of classes.
>
>
Pyd can easily return an array. It is the reverse operation (wrapping
functions with array parameters) which causes problems at the moment.
--
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org
More information about the Digitalmars-d
mailing list