[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How much lua?
- From: "Adam D. Moss" <adam@...>
- Date: Tue, 09 Dec 2003 10:14:33 +0000
i'm part of ps2 development team that uses lua. The question i have is this.
how much of the game should be in lua?
i know the answer is probably "it depends..." hehe but i'd like to hear if
anyone here have been to either end of the rainbow and what its like
there... what are the goods and bads...
Personally I try to move EVERYTHING non-time-critical into
lua. This amounts, for me, to 100% of the game-specific logic,
and a generous pinch of reusable utility-layer.
The game engine itself is C and handles the scene-graph traversal,
physics, graphic rendering, I/O, audio rendering, etc -- usual
Then I expose a fairly high-level API to the lua-side, mostly
oriented towards manipulating the scene-graph and some other
core engine-side structures that define the game world and
presentation. The fairly raw C API calls I expose are then
wrapped at the lua-side into more friendly and logical 'objects'
A lua-side game-logic init-script is booted at engine startup
and registers its interest in certain arbitrary engine events (i.e.
frame-end, key-release, os-level app-quit, etc). Engine events
cause synchronous callbacks in event observers through a system
that is language-agnostic and which can pass complex reflective
structures. In this manner at no point does the core of the C
engine know or care that it is talking to a lua script.
Now the game logic typically asks for a callback every frame through
its 'tick' function and is happy with that.
This is working out fine so far -- 100% of the game-specific logic
in Lua, 100% of the engine core in C, and a fairly thin hand-rolled
interface gluing them.
Why am I doing it like this?
* Game-level fixes and improvements (and bugs!) are platform-
neutral. This definitely helps QA and, potentially, the rollout
of fixes (modulo platform-specific installers and lua bytecode
wordsize incompatabilities [fortunately we don't support 64-bit
* Lua is generally more pleasant than C (or C++!) for high-level
object-oriented logic. It really helps that you can 'roll your
own' object and module systems just how you like them on top of
Lua's extensible semantics, though it takes some work.
* It's nice to have garbage collection.
* Can create (at the lua-side) and present an ultra-simplified
scripting interface to non-programmers for scripting level-specific
'switches and monsters' etc.
Now, a heavy disadvantage of moving logic to Lua is that Lua code
can be pretty tough to debug -- you lose the usefulness of the
development platform's logic-probing tools (i.e. gdb). (Similar
situation with profiling i.e. gprof.) These tools can be
reconstructed at the lua-side but that really takes a lot of
time (there are examples in the wiki but [last I checked] they're
very basic and also not ported to lua5). Still, there's always
the old print[f] debugging method...
Adam D. Moss . ,,^^ firstname.lastname@example.org http://www.foxbox.org/ co:3
Consume Less, Live More