Game Development Reference
In-Depth Information
tolua++
This library attempts to solve the problem of registering functions and classes to Lua
so they can be used in script. First, you go into your C++ code and tag the things you
want to expose with special comments. When you build your game, you run a simple
pre-process that scans your source tree and generates the binding C file that exports
these functions and classes for Lua. When your program compiles, these are all visi-
ble to Lua. We used this at Super-Ego Games very successfully.
The advantage of this system is that it
s trivial to export any function or class to the
script. You literally just tag the line with a // tolua_export comment, and the
pre-process does the rest. There are a few disadvantages, though. One of the biggest
disadvantages is that tolua++ is a one-way street. It
'
s not easy to call a Lua function
from within C++ code and read a Lua-specific data structure like a table. You can
return simple types like numbers and strings, but tables are much more difficult to
work with.
'
luabind
luabind solves a lot of the problems of two-way communication that tolua++ has by
wrapping a lot of the Lua C API functionality into classes. You can grab any Lua
variable, read it, iterate across its elements if it ' s a table, call it if it ' s a function, and
so on. You can expose C++ class, functions, and other objects to Lua, going back and
forth relatively easily. Overall, it
s a great system.
One big disadvantage of luabind is its reliance on boost, which includes a lot of over-
head. Some people don
'
'
t mind this much, but for others it
'
s a deal breaker.
LuaPlus
LuaPlus was created by Josh Jensen and has a lot of the same core functionality as
luabind, but it has absolutely no reliance on other libraries. It tends to run faster
and adds wide-string support to the core Lua library. Many of the same class and
function binding capabilities exist in LuaPlus as well. For these reasons, it is the bind-
ing system I have chosen for this topic.
LuaPlus does have a few disadvantages. First, it modifies the core Lua implementa-
tion. This is done for performance reasons and to add wide-string support. For some
people, modifying the core library is a deal breaker. Another slight flaw when com-
pared to luabind is that LuaPlus doesn
'
t include all of the same functionality,
although LuaPlus has more than enough for most purposes.
 
 
 
 
Search WWH ::




Custom Search