问题
I have a working c-bison-flex based project. I've started to build a python-tkinter environment for it, but I was fallen into a trap. I intended to copy the content of the tkinter's edit window to the buffer of 'c' application. There is no problem with text passing, I can reach the 'c' functions - but the buffer address is not known. The buffer is allocated by flex 'on the fly'. Any idea to workaround it? (Perhaps indifferent, but the system is Ubuntu.)
回答1:
flex
provides an interface for switching between different input buffers, including the possibility of specifying an in-memory input buffer with the functions yy_scan_string
and yy_scan_bytes
(See the Flex manual for details.)
As the manual says, these routines make a copy of the string, so you still don't know the address of the string in flex. But it does mean that you don't need to keep the string around after you've created the flex buffer, which is convenient when you're interfacing with scripting systems.
来源:https://stackoverflow.com/questions/20168245/how-to-pass-tkinter-text-to-flex