lua-users home
lua-l archive

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


On Sat, Nov 18, 2006 at 02:12:53AM -0800, Don Hopkins wrote:
> Since everybody wants to roll their own object system in Lua, it would 
> cool to parameterize the SWIG Lua runtime templates so you can hook in 
> glue for any object system you want. But for now I just hacked my own in!

Warning: [OT]

<rant>
I'm not part of that everybody!

Thats one of the things I never liked about scheme, and don't like
about lua either. The "hey, OO is easy, do it yourself in just 3 lines
of code!". The advantage of having an OO model builtin to the language
is it makes it easy to read people's code (you don't have to figure out
their flavor of OO first, LuaSocket, for example), and it makes it easy
for tools like swig to emit OO code in the language. As you say, swig
can't know the target OO system.

Anyhow, I put up with it in lua because luas has so many strengths when
used to extend C applications. Some of those strengths (small and fast,
a completely self-contained interpreter context that I can make multiple
instances of, good support for native threads, etc.) probaby derive from
the fact that it doesn't have an OO model or much of a standard library.
Still, it is a lack that I classify as a necessity of the
implementation, not a feature of the language.
</rant>

> I've found an easy way to plug a non-object-oriented C library into an 
> object oriented language is to write a thin C++ class around it, and 

Thats a good idea, and I'll definitely keep it in mind next time I try
and swig anything, thanks.

One downside is that it isn't necessarily faster for me to write a thin
C++ wrapper for a C library than it is to directly bind the C library
into the target language. Writing lua in C is pretty easy.

I guess where the approach would really shine, though, is when you
target multiple output languages.

I have a lib I'm binding into lua now, and I'll probably bind into ruby
later. I might try swigging it at some time, to see how the approach
compares to hand-writing the bindings.

Cheers,
Sam