beginner's pyd question - exporting structs to python

Laeeth Isharc via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Aug 18 09:39:33 PDT 2014


Hi there.

Brief introduction, and a beginner's question.

I just started playing with D a couple of weeks ago.  I have been 
programming in C on and off since the late 80s, but I do finance 
for a living and my programming skills grew rusty.  I have a bit 
more time now to catch up with developments, and D looks a very 
intriguing robust alternative to C when python won't cut the 
mustard.

I am trying to implement the Demark technical analysis indicators 
in D, and want to be able to call them from python.

So I have set up pyd okay, and the examples seem to work fine.  
Running on Fedora 20.  I am struggling a bit with the syntax on 
wrap_struct to export a struct and function returning a struct to 
python.  Here is what I have:

module hello2;

import pyd.pyd;
import std.stdio;
import std.conv;

struct t_mystruct {
   int i;
   string s;
};

t_mystruct hello(int[] inp) {
     int i;
     t_mystruct mystruct;

     mystruct.i=inp.length;
     mystruct.s="hello there";
     return mystruct;
}

extern(C) void PydMain() {
     def!(hello)();
     module_init();
     wrap_struct!(
       t_mystruct,
       "t_mystruct"
     );
}

Error:

def: hello
/root/anaconda/lib/python2.7/site-packages/celerid/infrastructure/pyd/def.d(151): 
Error: static assert  "string parameters must be wrapped with 
Docstring, Mode, etc"
/root/anaconda/lib/python2.7/site-packages/celerid/infrastructure/pyd/class_wrap.d(1474): 
        instantiated from here: Args!("", "", "t_mystruct", "", 
"t_mystruct")
hellostruct.d(30):        instantiated from here: 
wrap_struct!(t_mystruct, "t_mystruct")
error: command 'dmd' failed with exit status 1
[root at fedora demark]#

Apologies if it's in one of the examples - I did poke around, and 
couldn't see any obvious sample.

Many thanks.


Laeeth.


More information about the Digitalmars-d-learn mailing list