Original Post
Hello all, I have taken over a codebase with embedded TCL scripting and have been charged with adding embedded Python scripting too. Any advice appreciated! TCL seems to be a statement-based system where each line is a statement which is executed individually. Each of those statements runs a command, and that command gets passed in a pointer to client data. This makes it quite trivial to have a TCL statement such as "EditProperty 'attributename' 15" which can set "attributename" to 15, operating on an implicit object which was stored in the client data. Yet in Python, each callback for functions takes 2 PyObject pointers from the interpreter as arguments, and has to be a plain C function, so it has no prior context unless I use a global. Is there a way around this that I'm missing? I could try injecting the context into Python so it can be referenced explicitly, but then I have to attach all the functions to the object, and (work out how to) dereference the resulting 'self' object in each C++ function I bind. How would people go about this? At the moment I'm not sure which approach to take. Before anyone mentions it, Boost::Python is not available. I mainly have to do this with a very thin C++ layer, mainly just injecting variables from C++ and allowing callbacks into C++ from Python. Also, it would be handy to be able to execute existing TCL scripts from Python and vice versa. I know there are Tcl/Tk bindings in the Python standard library but I got the impression that they were mainly for GUI usage. Anybody know any better? I'm also going to check out tclpython later.