Forum

> > CS2D > Scripts > How to iterate a table from C/C++
Forums overviewCS2D overview Scripts overviewLog in to reply

English How to iterate a table from C/C++

2 replies
To the start Previous 1 Next To the start

old Re: How to iterate a table from C/C++

Flacko
User Off Offline

Quote
1
2
3
4
5
6
7
lua_pushnil(L); //This will be the key
while(lua_next(L,YOURINDEX) !=0)
{
	int k = lua_tointeger(L,-2); //Get the key
	int v = lua_tointeger(L,-1); //Get the value
	lua_pop(L,1); //Pop v from the stack and keep k for the next iteration (as we did when we pushed nil)
}
Where YOURINDEX you should place the stack index of the table you're trying to iterate
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview