|
Title: SWIG or tolua(++) for Games? Post by: Michael Buckley on May 27, 2009, 06:42:32 AM Hey, I don't want to start a flame war, but I was hoping to benefit from the experience of any TIG members who have used SWIG or tolua(++) in their projects before. I am at the point where I am about ready to add Lua scripting to my game, and I'm not sure about which tool I should use. I'll admit that I don't have a lot of experience with Lua (I wrote a simple poker game with it years ago), and am including it mainly because it is lightweight and most game modders already know how to use Lua.
My initial gut reaction was to go with SWIG to open up the possibility of Python scripting in the future. However, I had heard (again, years ago) that the code generated by SWIG was much larger and used more memory than the code generated by tolua, and I can't guarantee that I will actually ever need Python scripting. So I guess I'm asking, given the need for speed and memory efficiency unique to games, which of these tools is better suited for scripting games? Title: Re: SWIG or tolua(++) for Games? Post by: Klaim on May 27, 2009, 06:47:32 AM LuaBind (if you can use Boost).
Title: Re: SWIG or tolua(++) for Games? Post by: Michael Buckley on May 27, 2009, 06:52:43 AM Unfortunately, I cannot use Boost.
Title: Re: SWIG or tolua(++) for Games? Post by: Ivan on May 27, 2009, 09:43:46 AM I looked at SWIG and tolua++ when I was creating Lua bindings for my engine and I ended up going with SWIG, but I don't remember exactly why. In any case, I've been using SWIG and it's been working great!
Title: Re: SWIG or tolua(++) for Games? Post by: Michael Buckley on May 31, 2009, 06:38:18 PM Thank you both for your suggestions. I will try SWIG first.
Title: Re: SWIG or tolua(++) for Games? Post by: Kaelan on June 02, 2009, 04:17:50 PM LuaBind (if you can use Boost). LuaBind is neat, but I have to give it an emphatic 'stay away'. The template metaprogramming at work makes it very hard to understand, and it contains numerous bugs, some of which tremendously impair its performance. I ended up regretting using it at all for the last lua-related project I worked on.If you're a C++ metaprogramming genius, luabind might be the right choice for you - it's a good foundation to build a boost.python equivalent on top of - but if not, stay far away, because you'll never manage to get it to the point where you're happy with it. Title: Re: SWIG or tolua(++) for Games? Post by: Overkill on June 07, 2009, 01:37:53 AM I second Kael's opinion to stay away from LuaBind. This was once used in Verge, when we first added Lua support. It turned out to be extremely slow, buggy, and was completely incompatible once we needed to use pooled memory for strings (which made a sizeable performance difference on some platforms), to which the LuaBind developers pretty much said we were out of luck.
We ended up writing our own binding system, which is basically just regular Lua API calls, and actually has a fair deal of boilerplate done in Lua script itself. The normal Lua API isn't actually that bad, once you get the hang of it. Though it is sort of problematic for binding instances of classes directly to Lua, since you're using regular C code. But you can get around this with a little bit of userdata glue and upvalue things. I have no experience with SWIG or tolua++, though I have heard good things about SWIG in the past. I think it's less impressive though if you consider that it is extra tool you have to add in order to parse your source code. I personally like manually binding things to have more flexible control over the resulting Lua libraries. |