lua-users home
lua-l archive

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


Hello,

I'm new here, so apologies if this questions has been asked before...
I'm curious - is there any more detailed documentation somewhere about how
to use Lua to configure (and interact with) a C program?

We're going to use Lua as an embedded scripting language for our next game
and I'm starting by getting lua to load in tweakable numbers, obviously
hoping to expand on that later as I get to know the language a bit better.

At the moment, I'm using lua_getnumber(lua_getglobal("varname")) to load in
variables that I set in a script file.  Is this the best way?  Or is there a
way I can get Lua to point directly to (or change more actively) the
variables I'm setting?   In addition, how do I do the above with tables?
For example, I want to create tables that set the colours of procedurally
created graphics in the game, but the manual skips letting us know how to
load a table into a C program....

If my description is unclear, here's an illustrative example:

In a file called tweak.lua, I'd like to have the following lines:

-- configuration variables for the game
configVar1 = 10.0
configVar2 = 323.0
configVar3 = 5

-- configuration colour for the game
configColour = {255, 10, 10}   -- r,g,b deep red

-- etc...

In the game, I would have these same variables defined either locally in an
object or globally in a namespace, or whatever.  I set configVarX with the
lines

init()
{
	// read in configuration file
	lua_dofile("tweak.lua");

	// read in tweaked values for configuration variables
	configVar1 = lua_getnumber(lua_getglobal("configVar1"));
	configVar2 = lua_getnumber(lua_getglobal("configVar2")); 
	configVar3 = lua_getnumber(lua_getglobal("configVar3")); 
 
	// colours?
...
}


Am I doing this all wrong?  Or am I on the right track?

Thanks for any help you can give.

Falko Poiker
Programmer/Designer
Relic Entertainment Inc.
fpoiker@relic.com