lua-users home
lua-l archive

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


Brian,

Thanks. I will see how this works out.

Michael

----- Original Message ----- 
From: "Brian Hook" <hook_l@pyrogon.com>
To: "Lua list" <lua@bazar2.conectiva.com.br>
Sent: Monday, February 23, 2004 7:58 PM
Subject: Re: How to access array inside a table from C code ?


> I want to be able to access all the array entries, Array[1], ...
> from a C function. But I cannot seem to figure out how to do this. 
> Help would be appreicated.

In a nutshell, you do a lua_getglobal() to retrieve T, then do a 
pushliteral/rawget pair to get "Array", and then pushstring/rawget 
pairs to get individual elements.

Off the top of my head, something like:

lua_getglobal( L, "T" ); // T
lua_getpushliteral( L, "Array" ); // T : "Array"
lua_rawget( L, -2 ); // T.Array
lua_pushnumber( L, whatever ) ; // T.Array : index
lua_rawget( L, -2 ); // T.Array : whatever_was_at_Array[index]

etc. etc.

Brian