Recently, you are ready to use LUA in the Mobile Project client, which has been using Luabind on the server before. In addition, tolua++ also experienced, Luaplus also used in the early years. Here are my personal feelings about these bindings libraries:
Luabind
Using the boost mechanism to customize the binding to the extreme, more suitable for the main C + +, weak Lua script framework.
The author has stopped updating, the Windows/linux compilation is no problem, but under iOS LLVM, cannot compile
tolua++
Like COCOS2DX using tolua++ is understandable, so many functions need to be bound, tolua++ 's header file parse and automatic code generation save a lot of manual binding time.
But see a part of the code bugfix will be uneasy (pure personal feeling, I use not much, welcome brick to wait), in addition, tolua++ can only be driven by the script layer C + +, and not the already instantiated handle register to LUA function is also idiot AH
Luaplus
Interface is simple, suitable for beginners, without any template, performance is not high
Luabridge
Project Address: Https://github.com/vinniefalco/LuaBridge
Brochure: http://vinniefalco.com/LuaBridge/Manual.html
Pure header file implementation, without compiling, including entry into the project, interface simple and efficient
Compared to Luabind, the only common function that cannot be implemented is enumeration, but can support static variable registration of class member, this does not matter, handwritten an enumeration support is also very simple
Look at the demo code:
classa{ Public: A () {}Virtual voidFoointA) {printf ("Foo base\n"); } std::stringMember;};classB: Publica{ Public:Virtual voidFoointA) {printf ("Foo inherited\n"); }};
void int b) {}
Luabridge::getglobalnamespace (L) .beginclass<a> ("Sobj") .addconstructor<void(*) (void) > (). addfunction ("foo", &a::foo). AddData ("Member", &a::member). Endclass (). Deriveclass<b, A> ("SSec"). AddFunction ("foo", &b::foo). Endclass (); Luabridge::getglobalnamespace (L). AddFunction ("foo", foo); B ins; Ins. Member ="Data"; Luabridge::setglobal (L, INS,"INS");
"Hello"ins:foo (3)
Part of the test used in COCOS2DX:
Unzip directly, Copy all the header files under Luabridge.h,refcountedobject.h,refcountedptr.h and detail to the classes directory, and then appdelegate include Luabrigde.h.
the following is a class for testing
class TestA {public: TestA () {} int getValue () { return 100; }};Here is the binding code
Luabridge::getglobalnamespace (Pengine->getluastack ()->getluastate ()) .beginclass<testa> ("TestA" ) .addconstructor<void(*) () > (). AddFunction ("GetValue", &testa::getvalue). Endcla SS ();You can then use this class in your LUA code.
Local testa = Testa () cclog ("testa=%d", Testa:getvalue ())now COCOS2DX above, there are two important LUA branches, one is Quickx, the other is a cocos-code-ide.
Using the LUA hot update module