[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Indices in Lua
- From: Roberto Ierusalimschy <roberto@...>
- Date: Fri, 19 Jun 2009 17:03:17 -0300
>> table, no. table keys are lua objects, and numeric table indices are
> The above remark confuses me. The Lua Reference Manual on page 43 gives:
> lua_rawgeti (lua_State *L, int index, int n);
> Pushes onto the stack the value t[n] ...
> void lua_rawseti (lua_State *L, int index, int n);
> Does the equivalent of t[n] = v, ....
> That is "int n", which certainly is not a lua_Number (a "double"
> according to page 39). Or are these "int n"-s pointing to something else
> than a "numeric table index" pointing into table t?
This "int n" is translated to a "double n" in the obvious way. Ints may
be converted without loss to lua numbers for any reasonable definition
of lua_Number. Contrary to the above remark, you should be able
to use ints safely in the API. (In particular, lua_objlen applied to
tables should always return values that fit in ints and size_t.)