Re: is there a way to embed python 3.7 code in D program?

2019-05-19 Thread torea via Digitalmars-d-learn

On Monday, 13 May 2019 at 03:06:07 UTC, evilrat wrote:

On Monday, 13 May 2019 at 01:35:58 UTC, evilrat wrote:


I have project using pyd with python 3.7, that also using 
ptvsd (visual studio debugger for python package) to allow 
mixed debugging right inside VS Code.


I'll reduce the code and upload somewhere later.



https://github.com/Superbelko/pyd-min

Here. Super minimal example, ptvsd can be commented out as 
well, it is there entirely for debugging.


Your example helped me a lot!
Thank you evilrat!


Re: is there a way to embed python 3.7 code in D program?

2019-05-14 Thread torea via Digitalmars-d-learn

On Monday, 13 May 2019 at 08:33:46 UTC, Russel Winder wrote:
I'd like to use D for the "brain" of a small robot (Anki 
vector)

whose API is coded in Python 3.6+.
I had a look at Pyd but it's limited to python 2.7...


PyD works entirely fine for me using Python 3.7.



Yes, it seems to work so far for me too, just modifying the 
dub.json file.


Thank you all for the tips!!



Re: is there a way to embed python 3.7 code in D program?

2019-05-12 Thread torea via Digitalmars-d-learn

On Sunday, 12 May 2019 at 21:01:31 UTC, Nicholas Wilson wrote:

On Sunday, 12 May 2019 at 20:06:34 UTC, torea wrote:

Hi,

I'd like to use D for the "brain" of a small robot (Anki 
vector) whose API is coded in Python 3.6+.

I had a look at Pyd but it's limited to python 2.7...


It isn't. You may needs to set a dub version, or it may pick up 
the 2.7 as the default but it definitely works (I'm travelling 
ATM, can't check).


ok, I'll do some more tests with pyd then.
And if I cannot get it to work, I'll have a look at the package!

Many thanks!!


is there a way to embed python 3.7 code in D program?

2019-05-12 Thread torea via Digitalmars-d-learn

Hi,

I'd like to use D for the "brain" of a small robot (Anki vector) 
whose API is coded in Python 3.6+.

I had a look at Pyd but it's limited to python 2.7...
Would there be other ways to call python functions and retrieve 
the python objects (including camera image) inside a D program?


Best regards


Re: string mixup problem with stdin.byLine

2016-08-10 Thread torea via Digitalmars-d-learn

On Monday, 8 August 2016 at 16:30:39 UTC, Meta wrote:
Alternatively you can use std.stdio.byLineCopy and don't need 
to add the `to!string`. If you are calling to!string on ever 
line there will probably be no performance difference, but if 
you are not, such as only calling to!string on every *second* 
line or something like that, you should stick with byLine and 
calling to!string when needed.


Thanks for the additional tip!


Re: string mixup problem with stdin.byLine

2016-08-10 Thread torea via Digitalmars-d-learn

On Monday, 8 August 2016 at 12:29:51 UTC, Seb wrote:


You should always carefully read the description and Notes ;-)


Note:
Each front will not persist after popFront is called, so the 
caller must copy its contents (e.g. by calling to!string) when 
retention is needed. If the caller needs to retain a copy of 
every line, use the byLineCopy function instead.


http://dlang.org/phobos/std_stdio.html#.File.byLine

Unfortunately you are not the first one who bumped into this 
problem and this non intuitive behavior of byLine is heavily 
disputed.


Duh... I've read the documentation but managed to jump over these 
explanations... reading carefully would have saved me some pain!

Hopefully I'll be more careful next time.


Re: string mixup problem with stdin.byLine

2016-08-08 Thread torea via Digitalmars-d-learn

On Monday, 8 August 2016 at 05:17:24 UTC, Dave Akers wrote:

I do believe your problem is with the line...
On Monday, 8 August 2016 at 02:44:20 UTC, torea wrote:

string cleanLine = strip( cast(string)line );
It's casting a char[] to and immutable(char)[], causing the 
mutable buffer from byLine to be used as a string. what you 
want is...

string cleanLine = strip( to!string(line) );
which should make a copy of the mutable buffer.

I still a beginner at D but I think that will fix your problem.

-Dave


Problem fixed!!
Thank you very much for the solution and the explanation!


string mixup problem with stdin.byLine

2016-08-07 Thread torea via Digitalmars-d-learn

Hi all,

I'm still at beginner level in D and trying to make a simple note 
program in the terminal.
I've been struggling with a simple problem for the last 2 hours 
so I could use some help!


What I want to do is:
if I write #m, I record the following lines in a specific string 
member of a class, if I write #r, I record the following lines in 
another string member.

Here is the problematic part of my code :

bool stop = false;
auto enr = new Enreg();	// class Enreg{ public: string motsCles; 
string resume; }

enr.motsCles = "";
bool mode_motsCles = false;
bool mode_resume = false;
foreach( line; stdin.byLine ) {
writeln( enr.motsCles );  // modified when I pressed #r 
string cleanLine = strip( cast(string)line );
	string[] words = split( cleanLine );	// la phrase est separee en 
mots


switch( words[0] ){
case "##":
stop = true;
break;
case "#m":
mode_motsCles = true;
mode_resume = false;
enr.motsCles = "";
break;
case "#r":
mode_resume = true;
mode_motsCles = false;
enr.resume = "";
break;
default: break;
}
if( stop ) break;

if( cleanLine[0] == '#' ) continue;
if( mode_motsCles ){
enr.motsCles = cleanLine;
}else if( mode_resume ){
enr.resume ~= cleanLine ~"\\n";
}
writeln( enr.motsCles );
}

when I press :
  #m 
  things;stuffs; 
at the end of my foreach, i have enr.motsCles initialized 
correctly with "things;stuffs;"

If I continue with :
  #r 
enr.motsCles is modified at the very beginning of the loop and 
contain "#r\nings;stuffs;"


Anyone has an idea about what's going bad with my code?


Re: DerelictOrg and SDL_Mixer

2014-11-25 Thread torea via Digitalmars-d-learn

On Wednesday, 26 November 2014 at 01:25:51 UTC, Mike Parker wrote:
Don't think of it that way. Think of it this way: you have to 
load every library you want to use. SDL2_mixer is a library, 
SDL2_image is a library, SDL2_ttf is a library, and so on. You 
have to load them individually. DerelictSDL2 binds to SDL2, 
DerelictSDL2Mixer binds to SDL2_mixer and so on.




OK!
Somehow I had overlooked the most obvious documentation on 
DerelictSDL2: the readme.md file on the github repository page 
which displays these informations.. Sorry!


The Derelict packages are all just bindings to C libraries and 
nothing more. To use those libraries, you need to install their 
dependencies on each platform you need to use them on. If you 
don't know what the dependencies are, you should visit the 
website or support forums for that library.


Yes, it was an issue unrelated to D or DerelictOrg but still some 
problem encountered by clueless me on its quest to use SDL_Mixer 
functions with D.. This might be of some help for a beginner like 
me who had difficulties to find some straightforward 
documentation to set everything up. The SDL and SDL_mixer 
websites did not help much (..or I overlooked some stuffs again).


DerelictOrg and SDL_Mixer

2014-11-24 Thread torea via Digitalmars-d-learn

Hi all,

I'm playing a bit with D and SDL using DerelictOrg on debian 6. 
I've installed SDL2, SDL_mixer2 and the latest packages 
DerelictUtil and DerelictSDL2.

I can display some stuffs and interact with the keys.
Now I'm trying to add music and sounds but each time I try to 
access a function from SDL_mixer ( I tried with Mix_openAudio and 
Mix_LoadWav ), I get a segmentation fault.
These functions are defined in the mixer.d file in the 
DerelictSDL2 package but I guess I miss something concerning the 
link to the real sdl_mixer lib file.
Is there a specific way to install the sdl_mixer package with 
DerelictSDL2?


Re: DerelictOrg and SDL_Mixer

2014-11-24 Thread torea via Digitalmars-d-learn

On Monday, 24 November 2014 at 23:27:58 UTC, Jack wrote:
It's a common error but did you load the Mixer and SDL 
libraries?

DerelictSDL2Mixer.load();
DerelictSDL2.load();

And some code or output from gdb would be most helpful.


Oh.. I didn't know about the DerelictSDL2Mixer.load()!
I thought the initialization of sdl_mixer was done with 
DerelictSDL2.load()


Thanks very much!! I'll try this tonight!
(And yes, I know it's better to post some code but I forgot to 
bring the source code..)