Reputation: 769
I have this array:
a = {{4,2,2,6}, {2,1,1,2}}
How can I retrieve an index from that array to a C program?
For example:
a[1] -- {4,2,2,6}
a[1][2] -- 2
Upvotes: 3
Views: 3131
Reputation: 72422
Try this:
lua_getglobal(L,"a")
lua_rawgeti(L,-1,1)
lua_rawgeti(L,-1,2)
After this, the value of a[1][2]
will be on the top of the stack. The stack will also contain a
and a[1]
, which you may want to pop when you're done (they're left on the stack in case you want to retrieve multiple values).
Upvotes: 3
Reputation: 11716
You can use the lua_gettable
method. There are a few important notes, however:
lua_pushinteger
.Upvotes: 6