[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Some Lua & SWIG questions
- From: "mark gossage" <mark@...>
- Date: Sun, 15 Jul 2007 20:31:59 -0600
> I'm writing a binding that allows Lua to be used for describing 3d
> scenes intended for rendering with a high-end 3d renderer like Pixar's
> PhotoRealistic RenderMan or DNASoft's 3Delight. The target audience for
> this is foremost the visual effects industry.
> This requires me to support some more exotic things.
> 1. Lua source files that may be compressed (gzip, bzip2, etc.) and may
> contain binary chunks of data (essentially rendering the source file
> partly non human-readable).
> 2. It also requires functions with variable-length argument lists
> (arguments being of arbitrary type, detected at runtime).
> I have all this working already well 'by hand'.
> However, with my codebase growing and me spending a lot of time
> maintaining code that is doing these things (vs code that does things
> interesting to the functionality provided by the binding itself), I was
> wondering if people here have experience with SWIG and how it handles 1.
> & 2.
> I also will have to do a Python binding for this next which seems
> another strong point to use something like SWIG.
> I couldn't find anything about variable-length argument list functions
> in the SWIG Lua docs.
> I'm also unsure about how much control I have over loading code (to do
> decompressing and turning binary chunks into user data pointers
> on-the-fly, as I currently do) before handing it over to the actual
> And just in general, what are people's experiences when going from a
> 'hand-written' binding to a binding generation framework like SWIG?
There is a big bunch of questions in this mail, I will try to address some of them.
On the topic of va-args within Lua-SWIG, sorry there is not too much support for this. http://swig.sourceforge.net/Doc1.3/Varargs.html covers the basics, but there is no good standard way to do it.
Personally when I have printf style functions to wrap, I just produce a simple do_func(const char*) and then write some lua code using string.format() to call do_func(). That works nicely.
The SWIG typemaps code means that if you do have a good way to parse the arguments, you can write it as a typemap & then SWIG will then use this everywhere, which makes the whole process a lot less error prone. This is a good feature.
Another good thing you can do, is to use the %native command, which allows you to add your own hand wrappered functions into the binding. Since Lua makes is easy to roll your own wrappers, this is very handy.
On the topics of compressed scripts & such, I have no idea, but if you have written it yourself, it should be easy to migrate to SWIG.
If you want help on writing the typemaps for the va-args, give me an example on how you do it currently, and I can help on turning it into a typemap.