lua-users home
lua-l archive

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

Sam Roberts <> writes:
>> However for a newbie that isnt familiar with the C API and hasnt got much
>> time to create some bindings I would say the sensible and proper way to get
>> a quick bug free solution is to use something such as Swig.
> Assuming swig is easier to use than lua's C api.

It is.

Maybe "easier" is not quite the right word:  Lua's C API is easy enough
to use, but it requires a lot of grunt-work in writing thunk routines,
even for very straight-forward C interfaces.  For C++ interfaces, where
one wants to export C++ classes and all their associated semantics,
things get more complicated.

Swig by comparison is "occasionally annoying but usually almost
trivial", and this is especially the case for C++ object hierarchies.

> My experience with swig is that that isn't true, and that you end up
> having to know both the C API of the language you are binding to and a
> fair bit of swig internals.
> I have the impression swig works better when binding C++ to an object
> oriented language,

I think that's a mistaken impression.  Swig does a _very_ good job
binding Lua and C++.  It almost always does "the right thing", so one
doesn't have to worry about it most of the time.

Of course, very occasionally something isn't quite right, but swig
offers some powerful mechanisms that can be used to help fix things.
The important thing is that for the 99% of the interface that _doesn't_
need special treatment, using swig is dead easy...

If I were binding a simple C library, maybe I'd use something else, but
for a language like C++, swig is a very good tool.


Quidquid latine dictum sit, altum viditur.