🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

LUA: table reading

Started by
2 comments, last by Filami 21 years ago
Hi ppl... I''m having some trouble reading a table from a lua script in c++: Lua:
p = {5,1}
readtable(p) 
C++:
int l_readtable(lua_State* luaVM){
	if(lua_istable(luaVM,-1)){
		lua_pushnumber(luaVM,0);
		lua_gettable(luaVM,1);
		int obj = (int)lua_tonumber(luaVM,-1);
	}
	return 0;
}
 
I don''t know why but obj (that should have a value form the table) is always 0 and no element from the table is 0, Why? What I''m doing wrong? Filami
Techno Grooves
Advertisement
table constructors like {5, 1} count their indices from 1, not 0. Change the call to lua_pushnumber(luaVM, 1) and it''ll return 5.

How appropriate. You fight like a cow.
[IMG]http://www.saunalahti.fi/~atjw/smile/smilies/war/2gunsfiring.gif[/IMG] I just can''t belive that!!! [IMG]http://www.saunalahti.fi/~atjw/smile/smilies/evil/evil3.gif[/IMG]
So much time in front of this for a realy but realy simple thing....

Filami
Techno Grooves
[IMG]http://www.saunalahti.fi/~atjw/smile/smilies/war/2gunsfiring.gif[/IMG] I just can''t belive that!!! [IMG]http://www.saunalahti.fi/~atjw/smile/smilies/evil/evil3.gif[/IMG]
So much time in front of this for a realy but realy simple thing....

Filami
Techno Grooves

This topic is closed to new replies.

Advertisement