lua-users home
lua-l archive

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


>From: Falko Poiker <fpoiker@relic.com>
>
>I'm new here, so apologies if this questions has been asked before...

Some of it has been :-) Check the lua-l archives.

>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?

Yes, that's the natural way, except that if "varname" does not contain a
number you'll get 0 and no warnings. You may want to use lua_isnumber before
calling lua_getglobal.

>Or is there a
>way I can get Lua to point directly to (or change more actively) the
>variables I'm setting?

Yes, there's a way: use user data and "getglobal"/"setglobal" tag methods,
but you'll have to program these.
The tolua tool is probably your best option here if you want to export many
variables, of many diferent types.

>In addition, how do I do the above with tables?

Use lua_gettable.
Again, tolua is very useful here because it handles structs too.
--lhf