Re: [q-lang-users] windoze libraries question
Brought to you by:
agraef
From: Albert G. <Dr....@t-...> - 2007-03-20 19:45:54
|
Evan Hawkins wrote: > What is the procedure to make these libraries "available" to Q? Which libraries exactly? The Windows APIs are huge. :) For moderately-sized APIs, there's Q's native C interface (see Appendix C of the manual, http://q-lang.sourceforge.net/qdoc/qdoc_15.html#SEC156). The biggest Q module written using that to date is clib, Q's POSIX system interface, you can find the sources of that in the Q source package, http://prdownloads.sourceforge.net/q-lang/q-7.6.tar.gz?download The direct C interface is probably easier to understand, but for bigger libraries your best bet would be SWIG, because it generates most of the necessary wrapper code for you. There's a Q-enabled SWIG version available on the Q website (and a binary for Q-SWIG is already included in the Qpad package): http://prdownloads.sourceforge.net/q-lang/swig-1.3.22-q-20060225.tar.gz?download Unfortunately, there's no specific Q-SWIG documentation yet (beyond the generic SWIG 1.3.22 documentation). However, two basic examples can be found in the Qpad/examples/swig folder, more examples are included in the Q-SWIG source package (see the link above), and some of the modules (e.g., Q's interfaces to OpenGL, SQLite etc.) are also written using SWIG, so you can study the sources of those (all available at http://q-lang.sourceforge.net/download.html#Sources) to see how to deal with full-blown libraries. (But make sure to take a look at the basic examples first. It's also instructive to look at the generated C/C++ wrapper code to better understand SWIG's inner workings. Essentially it's all about marshalling Q data to C, running the C function, then converting C/C++ results back to Q.) For simple interfaces it's often just a matter of writing a minimal SWIG interface (.i) file which either pulls in the necessary C/C++ header files or just declares the prototypes of the required functions. Q-SWIG already "knows" about simple C data types like numbers and strings and generic pointers, but if you need to wrap elaborate data structures, you'll probably need to supply your own "typemaps" to tell SWIG how to deal with them. The most complex issues arise if your C/C++ code needs to call back into Q, but this can be done, too, if done properly (you can find examples of this, e.g., in the OpenGL and SQLite modules). HTH, Albert -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikinformatik.uni-mainz.de/ag |