[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: C/C++ bindings: automated or by hand?
- From: "Erik Cassel" <erik@...>
- Date: Sat, 8 Sep 2007 08:56:38 -0700
I bind by hand, but I didn't set out to do so: My app already had a
reflection mechanism. All I did was create an adapter between the reflection
system and Lua. In one stroke I had 100% binding to all classes, functions,
properties and events.
Perhaps I'm stating the obvious, but the problem is that C++ has no
standardized reflection framework. If you set out to use (or reuse) a
reflectable object model (such as COM, managed C++, or homebrew) then the
bindings become trivial, and your code can easily be connected to streaming
systems, GUIs, etc. The possibilities go far beyond Lua.
> -----Original Message-----
> From: firstname.lastname@example.org [mailto:lua-
> email@example.com] On Behalf Of Jérôme Vuarand
> Sent: Friday, September 07, 2007 11:28 PM
> To: Lua list
> Subject: Re: C/C++ bindings: automated or by hand?
> 2007/9/7, Daniel Collins <firstname.lastname@example.org>:
> > I was just wondering how most people here bind there native code to lua.
> > [...]
> > So what are the thoughts and experiences of others here on this issue?
> So far I've done all my bindings by hand. All third-party APIs I've
> bound to Lua (for example win32, libpng, freetype, opengl, ode, fuse,
> etc.) were so different from each other that each time I had to take a
> different binding style. At the beginning I thought that I lacked
> experience, but when I come back to mu old bindings I rarely see how I
> could rewrite them better.
> Among techniques that are adapted to some libs but not to others :
> - everything written by hand vs. a little Lua script generates the binding
> - C++ templates vs. C macros vs. nothing generic
> - a C file per function
> - all C vs. a C core and a Lua wrapper
> - metatable per object vs. metatable per class
> - environment per object vs. environment per class vs. no environment
> All these choices are valid and each appeared to be the best for some
> lib I bound in the past. For my personnal libs, I try to be more
> consistent, but I still bind them by hand.
> Advantages I see in doing hand-written bindings:
> - using the lib in Lua code is easier, more natural and adapted to the
> language, eventually reusing some aspect of the standard lib API that
> everyone knows ('file' object methods for example)
> - you can keep the paradigm and syntax style preferred by the lib, it
> makes porting examples and tutorials straightforward, and let you
> redirect to the original documentation
> Also an important point is that since it requires much more work, I
> tend to make only partial bindings (ie. I don't expose all functions).
> This is an advantage in the sense that I only bind methods that I use
> (and so I test them all), but it could prevent other people from using
> the lib as is (but I have enough spare time to address all eventual
> request I have to complete my bindings).