lua-users home
lua-l archive

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


I've had same experience. One issue is that if you program in multiple languages you can't remember all the details (or maybe I'm just getting old ;) Plus a lot of exposing C/C++ classes and functions to Lua is repetitive, boiler plate code, and it's easy to make indexing mistakes when using the Lua stack. So I use SWIG so I don't have to worry about __index, stack indices etc. I create pure c++ libs then let SWIG do all the binding to allow me to use them from Lua. And when I need to script a C++ application with Lua (rather than extend Lua with a C++ lib), I use SWIG in conjunction with an OO wrapper lib (plug-alert: like lua-icxx, which I wrote; see http://lua-icxx.sf.net). 

Performance impact is oft mentioned as main reason for *not* using a code generator like SWIG or tolua++. That makes me smile because a C++ compiler is a code generator (generates machine code). Surely you can write assembly that is more efficent than C++. Maybe. Once in a rare while. With more time. More bugs. And less maintainable and understandable. Also, IME "realworld" apps do way more than run Lua scripts (from C++) or call c++ lib from Lua; such as file and network access etc. And design decisions tend to have a much greater impact, like how often do game entities get (re-)created, how often do you run queries on a database, how much state you store locally vs on server, use of caching etc. So the impact of SWIG-generated code over rolling my own has been negligeable in performance and significantly positive in implementation time and maintainability. 

Note: I have no stake in SWIG. I'm just glad it supports Lua, yet I get the impression many people who find __index etc a pain don't know about it. 

Cheers, 
Oliver

On Sun, Aug 28, 2011 at 2:45 PM, Mark Hamburg <mark@grubmah.com> wrote:
This thread plays a bit to a message I started a while ago and never finished. Metatables are "hard" -- particularly for people coming from backgrounds in OOP languages. This message is not about potential changes to Lua but rather is an attempt to understand why people get confused so often.