I'd like to announce a new Lua binding library for C++11.
If you all remember this thread I said I might make a fancier binding library. That is what I ended up doing.
I've posted it on github, and its licensed under the Zlib license.
It is not currently complete, a few things could use some improvement, and I have no idea what the performance or memory use is like.
Patches welcome
https://github.com/Tomasu/LuaGlue
Obligitory example:
lua:
local test = Foo.new(333); test:abc(1,2,3); print("ONE: "..Foo.ONE); print("TWO: "..Foo.TWO); print("THREE: "..Foo.THREE);
C++
Output:
ctor! 333 1:2:3 ONE: 1 TWO: 2 THREE: three
]]>
I love the simplicity. Question: does it support interfaces or inheritance? That's something that's bothered me about previous glue libraries...
E.g., say I have a data class/interface (like LOVE does in some form) and then have a generic WriteData method. Can I pass it a BitmapData, or AudioData, or FooData?
I'll take a look at the code soon. Previous libraries aimed at 5.1.x have way too much template trickery going on...
]]>Question: does it support interfaces or inheritance? That's something that's bothered me about previous glue libraries...
I haven't tested it, but I don't think it'll get in the way[1]. But you can't define any kind of inheritance, and the library currently treats lua as a second class citizen, as in lua cant subclass you classes.
To support a fuller OO experience would probably require something as crazy as luabind.
Previous libraries aimed at 5.1.x have way too much template trickery going on...
You are not going to enjoy LuaGlue then. That simplicity is made possible by the template magic. The new C++11 variable argument templates especially so.
You are not going to enjoy LuaGlue then.
Your code is many times cleaner than Luabind (I'm sure it's thanks to C++11 features). The templates and macros and Boost dependency meant only a C++ guru could understand Luabind. So I guess I should've said preprocessor hacks...
]]>Your code is many times cleaner than Luabind (I'm sure it's thanks to C++11 features).
Thanks... I think?
Your code is many times cleaner than Luabind (I'm sure it's thanks to C++11 features). The templates and macros and Boost dependency meant only a C++ guru could understand Luabind. So I guess I should've said preprocessor hacks...
Yeah, I'm not fond of the boost magic they have going on. A lot of it is done with some magic boost preprocessor stuff. It is really hard to follow.
Making some decent progress on the binding, as I try to use it for one of my projects. Last few things that got added are:
The ability to bind a destructor method that gets called when lua gc's the userdata, it will not call your object's destructor, but you could do that yourself.
Passing glued objects between lua and C++ and have them be properly converted between raw object pointer and lua userdata as needed.
Passing unglued objects between lua and C++ as lightuserdata, also being converted as needed.
extended example:
C++
Lua:
local test = Foo.new(333); test:abc(1,2,3); print("ONE: "..Foo.ONE); print("TWO: "..Foo.TWO); print("THREE: "..Foo.THREE); local ptrtest = test:ptrTest(); test:ptrArgTest(test); test = nil; collectgarbage();
Output:
ctor! 333 1:2:3 ONE: 1 TWO: 2.12 THREE: three 4:4:4 ptrArgTest: 0x17090d0 abc:143
I seem to have made the dtor/gc method call not work, potentially the test object has been left on the stack at some point. I'll have to ferret that out.
]]>I really should try this. Maybe I could get back on some non web development again...
]]>