[Pymat-users] Adding engOutputBuffer
Brought to you by:
ajssf
From: Koen V. <ko...@ph...> - 2003-09-23 08:01:16
|
Hi, Recently, I tried to call Matlab from C, and started with the examples provided by MathWorks. This wasn't a problem, so I moved to Python. After spending some time trying to install PyMat, I got it to work as well, but the Python equivalent of engOutputBuffer was missing. So, since I never did any Python<->C programming and I'm always looking for new things to try, I decided to add it. I tried to copy the style in pymat.cpp. I'm not sure the thing is correct in any way (should I do Py_INCREF(Pbuf)? I don't know...), but it seemed to work when I tested it. See the attached file for the diff. Again, note that I did this just to see if I could and it might not be useful to anyone. But if you have any comments, I'd be happy to hear them. As a quick example, try to run: import pymat import array h=pymat.open() buf=array.array('c',250*['*']) print buf pymat.outputbuffer(h,buf) pymat.eval(h,'a=1+1+1') print buf s=buf.tostring() print s[0:s.find('\0')] pymat.eval(h,'b=a^2') s=buf.tostring() print s[0:s.find('\0')] pymat.outputbuffer(h,None) pymat.eval(h,'c=b-a') s=buf.tostring() print s[0:s.find('\0')] pymat.close(h) Koen |