www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - matplotlibD returns

reply Brett <Brett gmail.com> writes:
How does one get return values?

https://matplotlib.org/3.1.0/gallery/statistics/hist.html

Shows that python uses return values to set properties of the plot

https://github.com/koji-kojiro/matplotlib-d/blob/master/examples/source/app.d

Does not give any examples of return values and when trying gives 
error about void returns.
Sep 16 2019
parent reply jmh530 <john.michael.hall gmail.com> writes:
On Tuesday, 17 September 2019 at 01:54:01 UTC, Brett wrote:
 How does one get return values?

 https://matplotlib.org/3.1.0/gallery/statistics/hist.html

 Shows that python uses return values to set properties of the 
 plot

 https://github.com/koji-kojiro/matplotlib-d/blob/master/examples/source/app.d

 Does not give any examples of return values and when trying 
 gives error about void returns.
If I'm reading the following comment [1] correctly, this feature may require changes to matplotlib-d to implement. [1] https://github.com/koji-kojiro/matplotlib-d/issues/7#issuecomment-274001515
Sep 17 2019
parent Brett <Brett gmail.com> writes:
On Tuesday, 17 September 2019 at 15:21:37 UTC, jmh530 wrote:
 On Tuesday, 17 September 2019 at 01:54:01 UTC, Brett wrote:
 How does one get return values?

 https://matplotlib.org/3.1.0/gallery/statistics/hist.html

 Shows that python uses return values to set properties of the 
 plot

 https://github.com/koji-kojiro/matplotlib-d/blob/master/examples/source/app.d

 Does not give any examples of return values and when trying 
 gives error about void returns.
If I'm reading the following comment [1] correctly, this feature may require changes to matplotlib-d to implement. [1] https://github.com/koji-kojiro/matplotlib-d/issues/7#issuecomment-274001515
That was over 2 years ago, it seems he isn't interested in making it work. In his code he uses pipes... void call(string py_script) { import std.process: environment, pipeProcess, wait, Redirect; auto py_path = environment.get("MATPLOTLIB_D_PYTHON", "python3"); py_path = `python.exe`; auto pipes = pipeProcess(py_path, Redirect.stdin | Redirect.stderr); pipes.stdin.writeln(py_script); pipes.stdin.writeln("exit()"); pipes.stdin.close(); auto result = wait(pipes.pid); if (result != 0) { string error; foreach (line; pipes.stderr.byLine) error ~= line ~ "\n"; throw new Exception("\n\nERROR occurred in Python:\n" ~ error); } } Not sure if this can be modified to work with returns? I guess they could be exported through json and possible read and used? I don't see how it could work though since it seems that pointers will be returned. I don't know enough about python to know if some mechanism would work. Maybe some python code could be created to call D and pass info back and forth or some better interprocess communications can be used? He's essentially just send commands through text(py_script) that are executed on the python side of things. Nothing ever really takes place in D. I guess a return type could could done on the python side too but it would require modifying the code and would be overly complex.
Sep 17 2019