lua-users home
lua-l archive

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

I would really appreciate a small, real-world example of Lua being used in a
C or C++ app, preferably using toLua. I'm very interested in using Lua in my
game, and it's not that I don't understand the language, but I am not clear
on the best way to allow scripts to control the AI for the sprites in the
game. I need to allow my sprite scripts to control variables for the sprites
in the game (speed, position, etc), get information about the "playfield"
that the sprites are interacting with (for collisions, etc), get information
about other sprites on the playfield, and be able to create new sprites.

Ideally, when a new sprite is being created, the game will be able to supply
an arbitrary string that holds the sprite's name, and that sprite's
description will be loaded into memory, along with a script that has the
same name. This would allow users to create their own sprites with my sprite
editor, create scripts for the sprites, add those sprites to a level, and
when the sprites are created the game would need no hardcoded knowledge of
how the sprites are supposed to function -- the scripts would take care of
everything. It seems that it would make most sense for each sprite script to
have two required functions: an initialization function that would set some
parameters for the sprite, and a processSprite function that would update
the sprite each frame.

Being new to Lua, I'm not sure how to go about implementing this
functionality in the most efficient way. I've looked on the lua-users wiki
page and (though I might not have been searching hard enough), could find no
examples of C/C++ apps using Lua to provide functionality in the form of
loadable "module" scripts, like I have described above.

Are there any such resources available to take a look at and play with? I am
not only new to Lua, but new to embedded scripting languages in general.

Tim Conkling
Vaporware Software