[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re[2]: Using numbers as float
- From: Dmitriy Iassenev <iassenev@...>
- Date: Fri, 30 Jun 2006 11:35:21 +0300
hello,
we use floats in Lua, but there is a problem, which, probably, is
because of this change (we still use Lua 5.02). When iterating via a
table, which indices are numbers, runtime error occured:
"invalid key for 'next'"
Therefore we iterate via Lua tables in the following way (we presume
that table to iterate is on the top of the stack):
// standard cycle
lua_pushnil (state);
for ( ; lua_next(state,-2); )
lua_pop (state,1);
// modified cycle
lua_pushnil (state);
for ( ; lua_next(state,-2); ) {
// start of the magic change
if (lua_isnumber(state,-2)) {
lua_Number next = lua_tonumber(state,-2);
lua_pop (state,2);
lua_pushnumber (state,next);
continue;
}
// end of the magic change
lua_pop (state,1);
}
--
Best regards,
Dmitriy mailto:iassenev@gsc-game.kiev.ua