Resource for learning Lua to use with C++?

c++, lua

Solution

You may want to look at toLua++ or Luabind for C++ integration.

As far as learning lua itself goes, the Programming in Lua book or even the Lua Reference Manual shouldn't be out of your league at all; see the documentation section of the lua website.

The usual rule applies: read lots of other code when you're getting started. If it's your cup of tea, you could e.g. go dig though World of Warcraft addons for some (admittedly specialized) real-world examples.

And listen to the community: subscribe to some mailing lists, take a look at the lua-users resources (especially the wiki), et cetera.

I work at a game development company, and we use primarily C++ and lua together. We don't actually use Luabind or toLua++ yet (mostly just a lack of time to test and integrate them), but a few things we've learned:

- you'll want to make a choice between creating and destroying lua environments (lua_State instances) on demand and keeping one or more around; getting rid of them can alleviate memory issues and provide nice unpolluted execution environments

- take advantage of lua_pcall's ability to register a debug function, see discussion on Gamedev.net

- if you're on a memory budget, consider using `lua_setallocf` to change allocator behavior -- constrain it to its own area of memory to prevent fragmentation, and take advantage of a more efficient small object allocator (perhaps boost::pool) to reduce overhead (other ideas in an earlier answer)

- get a good lua-aware editor; we use SciTE and Crimson Editor a lot where I work

- pay some attention to your garbage collector, call gc with various arguments and see what works best for your performance and memory requirements; we've had games where full gc each frame was the right choice, and others where 10% per frame was the right choice

- when you get comfortable, reach out to metatables; altering `index` and `newindex` has proved especially useful for us

- oh, and coroutines are sexy

Problem

So I have heard that Lua is a good scripting language that ties into C++. Does anyone know some good resources for picking it up, for someone with lots of C++ experience?

Original source

Related problems