Hi. This is my first time using Micropython, please excuse my ignorance...
I cut and pasted the code from examples/embedding/hello-embed.c into my application.
The application threw an uncaught exception due to a setup problem with the stack. I fixed this by stepping through the full micropython executable (ie not the embedding example) and seeing that it did some extra stack setup that was missing from hello-embed.c. Adding calls to mp_stack_ctrl_init() and mp_pystack_init() fixed this problem. I only mention this in case it helps others in the future.
Now I need a way to capture the stdout and stderr streams so that I can render the output in my GUI. What's the best way to do that? I see that ultimately the print in the example ends up being written to stdout in fdfile_write() from ports/unix/file.c. I can hack in something at that level to call a callback in my application to transfer the buffer contents. But I'm wondering if Micropython already has an interface to allow me to capture stdout/stderr without modifying the Micropython code.
Embedding in a Windows GUI application
Re: Embedding in a Windows GUI application
See mpconfigport.h and mpprint.h: most printing happens via the objects mp_plat_print, mp_sys_stdout_print, mp_stderr_print. If you change their definition you change where the output ends up. Those are meant to be used to do what you want and it's a better solution than your callback approach because fdfile_write gets used for all writing, including writing to arbitrary files.
-
- Posts: 5
- Joined: Sun Oct 04, 2020 10:19 am
Re: Embedding in a Windows GUI application
OK, thanks for the pointers.