lua-users home
lua-l archive

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

> Hi to everyone,
>     Just a few questions regarding Lua...
> 1. Basically, what do I do so that my C++ program (it's a 
> game engine) can> read Lua code? I'd rather write scripts for several
> of my game> engine than code it internally.
> 2. Would I need to modify most (if not all) of my engine functions for
> integration to Lua (i.e. w/ the LUA_STATE * lstate)?
> 3. Are there any links to other sites which use Lua and made 
> available their
> source code (for reference)?

You'd be better off asking the converse question: what do I do so that Lua
can read my C++ code? Lua will be embedded in your application and you'll
pass control to Lua which can then call C++. In order to tell Lua which C++
it can call you bind some code to it. There are several different ways of
doing this. You can do it by hand using the default lauxlib (see the
standard Lua libraries for examples of its use). Other methods include C++
templates or a binding tool such as toLua.

There is a page on the wiki which might help (mmm must get round to
finishing that one day)

Projects which use Lua:
Not all supply source code. Perhaps the list should note which projects are
open source and what license?

> 1. Where should I address questions regarding toLua? (since I 

Use this list. There is no toLua list.

> 2. When compiling toLua on a Win32/VC6 system, what should I 
> compile it

There are two parts of toLua, a standalone bin, which parses your package
and generates your binding code, and a library part which you link with your
executable. The library part adds the extra functionality that toLua uses,
like arrays and inheritance.

> 3. How would I create a package file for toLua? Should I edit 
> my source code
> to comply for this, or will toLua just automatically generate 
> it from my
> source code? If this is so, what should I do then?

The quickest way is just to copy your C++ interface/header file and make a
.pkg file. Simplify it down to what you want Lua to be able to see. toLua
takes no notice of access, ie. public and private so you have to remove all
the private stuff. Its really not that much hassle to keep it up to date
with your source code. I tried adding comments to my interface files and
writing a script to parse and generate a package file automatically but your
C++ code turns into a mess and by the time you've done it you might as well
hand code the package file.

If you need an example of toLua packaging and how to structure Lua and toLua
have a look at Theres a binding to OpenGL, GLUT, GLUI
and my C++ classes using toLua. There is also some OpenGL samples in Lua.
(There are more examples in CVS). It contains all the VC6 projects and *nix
makefiles and also how to include compiled Lua in your code so you can hide
source or save distributing Lua files with your exe.