Re: How to enumerate a Lua table in C++?
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: How to enumerate a Lua table in C++?
- From: Gopalakrishnan Subramani <gopalakrishnan.subramani@...>
- Date: 2010年11月25日 17:38:41 +0530
Thanks for example. I feel difficult to understand the enumeration. Based on a example, I could iterate a table in Lua.
Does LuaBind help to iterate much easier?
Here the senario:
function get_table()
return { {1, 2, 3} }
end
I need to call the function and enumerate the value. Please help me.
Regards,
Krish
On Thu, Nov 25, 2010 at 4:42 PM, Drake Wilson
<drake@begriffli.ch> wrote:
Quoth Gopalakrishnan Subramani <gopalakrishnan.subramani@gmail.com>, on 2010年11月25日 16:35:22 +0530:
> I am trying to create a prototype, in that we have a Lua table and we want
> to enumerate the elements of the lua table in C++ and print them.
>
> How to enumerate a lua table in C++? To get the lua table, we call a lua
> function in C++ and that lua function returns the lua table.
>
> Any source code example would be appreciated.
Use lua_next, which is described quite well in the C API
documentation. Start with a nil key, then keep retrieving the next
element from the table until you get another nil back which means
you're done.
---> Drake Wilson