lua-users home
lua-l archive

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


I have been using Lua for this kind of thing for a while.


> What would actually be helpful is understanding the idioms that others
> (in my case, game developers) use when integrating Lua.  For example,
> common questions that have come up include:
>
> - how many Lua subsystems should I be using?
    We use just one instance of Lua.  (We may eventually have two, one on
the client,
    and one on the server.)

> - show I put multiple scripts in a file
    You can organize scripts in any way that you like.  I find it easier to
segregate
    scripts based on functionality.  You will probably want to put almost
all of
    your code in Lua functions.

> - where should I split the scripting language vs. C/C++
    This is beautifully flexible in Lua.  We often put things in Lua for
testing and evaluation,
    and if we find they are taking too long, or are too tightly integrated
in to the
    engine code, we move them to C++.  For things in C++ that we find we
want to
    have more control over, we move them in to Lua.

> - what is a common way of calling an "AI" routine written in Lua?
    There are two basic alternatives that we use.
        - dostring  -> This is the easy way to call a routine that takes no
arguments, and returns nothing.
        - lua_call  -> More complicated, and more flexible.
>
> I'm very impressed with Lua, but the reference manual is fairly dry and
> without examples of "real world" usage.  The other docs out there are
> fairly old and outdated.  I'm primarily relying on other people's source
> code at the moment.
>
The other thing you need to be careful about is garbage collection.  If you
ever return a
pointer to Lua, you will need to tie in to their garbage collection system
to make sure
you take care of it properly when Lua is done with it.  Otherwise you can
end up with
either memory leaks, or invalid pointer in Lua.

We have a lot of other nice Lua integration features.
1) Auto registration of C++ functions.
2) Ability to call class member functions from Lua.
3) Type safe pointer passing to and from Lua
4) Unified C++ function handler for C++ calls made from Lua.

There a libraries available (although I have never tried them) that
integrate C++ and lua
in a more automated way.  They would probably be worth looking in to.


Good Luck,  let me know if you have any questions.

--jnw