Context: Windows7, optionally MinGW
I'm thinking of writing a Tk interface for Lhogho. Short of reading the source of Tkinter, how does one write that kind of a wrapper? It's been done for C++, Perl, Python, Tcl and others.
Context: Windows7, optionally MinGW
I'm thinking of writing a Tk interface for Lhogho. Short of reading the source of Tkinter, how does one write that kind of a wrapper? It's been done for C++, Perl, Python, Tcl and others.
It depends on how close you want the mapping to be.
The trivial way is to embed a Tcl interpreter and just call Tcl_Eval()
or one of the other functions of that family with the right Tcl code as strings, thats pretty easy to do when you can link C libraries or DLLs.
Once you have that, you can start to make your interface more natural, and for example provide mappings from your languages datastructures to Tcl/Tk internals (Tcl_Obj*), mostly for performance, or to add appropriate wrappers to make the bindings more natural for your language. The main problem usually is to get the event loop working properly with your language.
Have a look at perls tcl::tk module or pythons Tkinter for an example of this.
A different way to do it was done by PerlTk, which tried to NOT embed a full Tcl interpreter. Works but is much harder to do, as Tk uses a significant amount of Tcl code for the not performance critical parts like default binding scripts etc.
Some examples of embedding Tcl/Tk and discussions can be found at: http://wiki.tcl.tk/2074