lua-users home
lua-l archive

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


Hello,

All global variables in Lua are stored in a table that is in the
LUA_GLOBALSINDEX index. You can get a global variable like you would get
a normal field in a table. That will put the wanted variable on the top
of the Lua stack.

lua_pushstring(L, s); lua_gettable(L, LUA_GLOBALSINDEX)

There is a macro on lua.h that does this for you. It's the
lua_getglobal(L,s) macro.

Thiago

-----Mensagem original-----
De: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] Em nome de Mike Atamas
Enviada em: Friday, September 12, 2003 7:17 AM
Para: lua@bazar2.conectiva.com.br
Assunto: C, Lua, variable passing

Hello,
	I am writing a C program which needs to get certain variables
from a lua script that it runs (lua_dofile). I read in the manual that
you would get this using the index of the variable. However, I have
several variables and I do not always know what order they will be in or
what values they could store. Is it possible to have lua pass C a
variable knowing only the name of the lua variable?

Mike
aelfgar@aelfgar.com

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.515 / Virus Database: 313 - Release Date: 9/1/2003
 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.515 / Virus Database: 313 - Release Date: 9/1/2003