lua-users home
lua-l archive

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


I'm sorry, but I guess I just don't understand the stack manipulation here.
For one thing, lua_rawget() returns void, so how does that get me the value
of the array element?

In addition, the parent class that I called "T" is subject to different
names as new classes are derived from T, so lua_getglobal() is out. I assume
I would get the class name from the stack using something like
lua_gettable( L, 1 ) ?

Thanks,

Michael

----- Original Message -----
From: "Michael Newberry" <mnewberry@axres.com>
To: "Lua list" <lua@bazar2.conectiva.com.br>
Sent: Monday, February 23, 2004 8:36 PM
Subject: Re: How to access array inside a table from C code ?


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