Re: D-DLLs & Python

2013-02-20 Thread Chris
On Wednesday, 20 February 2013 at 14:43:06 UTC, John Colvin wrote: On Wednesday, 20 February 2013 at 14:28:06 UTC, Chris wrote: On Wednesday, 20 February 2013 at 14:05:40 UTC, Mike Parker wrote: Your function is being called from Python, correct? Then in addition to the extern(C), the argument

Re: D-DLLs & Python

2013-02-20 Thread Chris
On Wednesday, 20 February 2013 at 14:36:56 UTC, bearophile wrote: Chris: extern (C) {export void printThis(char* str);} Maybe the D wiki should contain info to save some time and experiments to people. I agree and I am glad that the people on this forum are always willing to help. I will

Re: D-DLLs & Python

2013-02-20 Thread John Colvin
On Wednesday, 20 February 2013 at 14:28:06 UTC, Chris wrote: On Wednesday, 20 February 2013 at 14:05:40 UTC, Mike Parker wrote: Your function is being called from Python, correct? Then in addition to the extern(C), the argument needs to be a char*, not a D array or a reference to one. Correct

Re: D-DLLs & Python

2013-02-20 Thread bearophile
Chris: extern (C) {export void printThis(char* str);} Maybe the D wiki should contain info to save some time and experiments to people. Possible alternative syntax: extern(C) export void printThis(char* str); Also, think if you want some const: extern(C) export void printThis(const(char)

Re: D-DLLs & Python

2013-02-20 Thread Chris
On Wednesday, 20 February 2013 at 14:05:40 UTC, Mike Parker wrote: Your function is being called from Python, correct? Then in addition to the extern(C), the argument needs to be a char*, not a D array or a reference to one. Correct, and it works _now_*! The lines printf("Incoming printf: %s\

Re: D-DLLs & Python

2013-02-20 Thread Mike Parker
On Wednesday, 20 February 2013 at 12:48:53 UTC, Chris wrote: I tried extern (C) which has some advantages. However, it still doesn't produce the desired result (tried slicing too). extern(C) { export void synthesize(ref char[] str) { printf("Incoming printf: %s\n", &str); writ

Re: D-DLLs & Python

2013-02-20 Thread Chris
I tried extern (C) which has some advantages. However, it still doesn't produce the desired result (tried slicing too). extern(C) { export void synthesize(ref char[] str) { printf("Incoming printf: %s\n", &str); writefln("writefln %s", &str); writefln("writefln %s", to!

Re: D-DLLs & Python

2013-02-20 Thread Chris
On Tuesday, 19 February 2013 at 17:40:03 UTC, John Colvin wrote: D doesn't use null termination for it's strings, strings are immutable(char)[]. You can form a D slice from a pointer by going slice = ptr[0..length] where length is the length of the array the pointer represents. You can't just

Re: D-DLLs & Python

2013-02-19 Thread John Colvin
On Tuesday, 19 February 2013 at 19:06:47 UTC, jerro wrote: D doesn't use null termination for it's strings, strings are immutable(char)[]. You can form a D slice from a pointer by going slice = ptr[0..length] where length is the length of the array the pointer represents. You can't just take a

Re: D-DLLs & Python

2013-02-19 Thread jerro
D doesn't use null termination for it's strings, strings are immutable(char)[]. You can form a D slice from a pointer by going slice = ptr[0..length] where length is the length of the array the pointer represents. You can't just take a c style string and expect writeln to work with it. You ca

Re: D-DLLs & Python

2013-02-19 Thread John Colvin
On Tuesday, 19 February 2013 at 16:23:45 UTC, Chris wrote: I have written a DLL that I load into a Python program. Everything works fine (DLL is loaded via ctypes, functions can be called and are executed). Only the string handling is giving me a bit of a headache. The string in D is always com