lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hakki Dogusan wrote:
Don Hopkins wrote:
There are some other useful libraries that plug together with Cairo, that you might be interested in integrating with Lua:

[snipped about Cairo related libraries]

Those need a group work, IMHO. I want to implement core API first. It seems easy to get/compile your mentioned libraries in Linux, but not for Windows. I Google'd for a prebuild Cairo dll before compiling mine. The ones I found had other dependencies.

It's worth checking out pycairo, the Python cairo module, which is designed so other people can write their own modules that use Cairo. It has some good ideas that you could adopt, which will make it easy for other people to build on top of your work.

http://cairographics.org/pycairo/

Cairo is used by so many other libraries, and people are writing new libraries that use it, and integrating them with various scripting languages. So pycairo has defined a formal way for other Python extensions that want to use Cairo to extract and wrap a Cairo context (and other Cairo objects) from the Python wrappers that the pycairo module creates. There's a pycairo.h include file that gets installs in the system (so other modules can include it without violating privacy), so other modules can include pycairo.h and use a macro to get the Cairo context, without worrying about how it's represented.

For example, I wrote a cellular automata machine and a tile engine that draws with Cairo, which includes the pycairo.h header file, so it can be passed a cairo_t * context from Python to draw with.

Description:
http://mailman.laptop.org/pipermail/games/2007-April/000101.html

Source:
http://www.donhopkins.com/home/cam.tgz

When the tile engine module initializes, it uses the PyCairo_IMPORT macro to get a Pycairo_CAPI_t structure (which calls PyCObject_Import("cairo", "CAPI") to get the shared structure), which has references to all the Cairo types (as wrapped by Python types), conversion utility functions, etc.

Then I wrote a SWIG typemap (pycairo.i) for functions taking a cairo_t * and cairo_surface_t *, that automatically converts between the cairo objects and Python wrappers, by using the PycairoContext_GET and PycairoContext_FromContext macros, and using the PycairoContext_Type to do parameter type checking.

SWIG can painlessly wrap functions that pass Cairo types in and out of other Python modules that depend on Cairo, and the right stuff just happens automatically and safely, with proper error checking!

   -Don