lua-users home
lua-l archive

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

Hi All,

   We always like reinventing the wheel... I did it once, and still
working on it since then, my solution was SLB (Simple Lua binder) ,
now it's hosted at, I've been using it for a long time
but I never find time to document it all (its main drawback) but you
can have a loot at the tests to get an idea. For example:

                SLB::Class<Animal, SLB::Instance::NoCopy >("Unit_004::Animal")
                        .set("makeSound", &Animal::makeSound)

                        .set("canFly", &Duck::canFly)

                        .set("bites", &Dog::bites)

The project is here:

and some tests:

Int addition to be able of using C++ code, you can use hybrid classes
(C++ classes with some methods implemented in Lua):

     class HClass : public SLB::Hybrid<HClass>

                /* int get() { return LCall<int>("get"); } */

                /* void calc(int a, int b) { return LCall<void, int,
int>("calc"); } */


 in the script:

function HClass:calc(a,b)
        result = a+b

-- create one instance
v = HClass()

-- another function:
function HClass:get()
        return result


(result variable is stored in a private table per instance, so you can
extend classes attributes)


On Wed, Dec 9, 2009 at 1:05 PM, liam mail <> wrote:
> 2009/12/9 Carsten Fuchs <>
>> Hi Martin,
>> Martin C. Martin schrieb:
>>> What libraries would someone recommend for binding Lua to parts of a
>>> large, existing C++ code base?  It needs to work in both Windows and Linux.
>>>  I'm looking at LuaPlus (I know, it's a lot more than just a C++ binding),
>>> but perhaps that's not the place to start?
>> When I started binding Lua to my C++ code in the Cafu game engine
>> <>, my goals were to keep everything as straightforward
>>  and with as few additional layers of code as possible, and thus, although I
>> looked into them, I never used any of the available C++-binding libraries,
>> but just the techniques explained in the PiL2 book.
>> While this route certainly takes longer in order to see the first results
>> and in fact may seem cumbersome in a sense (yes, you start thinking about
>> putting the resulting code into a library of your own... which in a sense
>> means re-inventing the wheel), I still found the results worthwhile: My code
>> is very short, clean, and I fully understand all the details both on the Lua
>> and on the C++ side.  :-)  (And I thoroughly learned Lua and its C API this
>> way.)
>> So my recommendation is to start with the PiL2 book, and only turn to the
>> libraries if you cannot or don't want to take the "hand-made" approach.
>> Best regards,
>> Carsten
>> --
>>     Cafu - The Game and Graphics Engine for
>> multiplayer, cross-platform, real-time 3D Action
>>            Learn more at
> It depends on what you want from the library which one you should try. For
> example as you want it to be cross platform that rules out a couple of them.
> Do you want it to use vanilla Lua or are you OK with it making adjustment to
> the Lua core, remembering that many addons and debuggers for Lua with a
> changed core may not work. Then there seems to be some with are no longer in
> development and also do you want to preform the binding yourself or do you
> want it to be automatic and the library parses your input files?
> If you are thinking of going down the reinvent the wheel route the there is
> a comparision of the different methods in IIRC Game Programming Gems 6, also
> some details to consider in an article in Lua Programming Gems. Personally I
> would say do not invest the time in reinventing the wheel and instead use a
> try and tested library, yet if everyone did this there would not be so many
> options (I hold my hand up :) ).
> Sorry but if I were to recommend a library it would be a biased answer so I
> will leave it at that.
> Liam

  Jose L. Hidalgo Valiño (PpluX)
  ---- ----