lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> In Lua API, the basic C int type is essentially used for stack indexes
> (why not) and for boolean values (since C89 does not have a bool
> type).
> The functions lua_rawgeti, lua_rawseti and lua_createtable somewhat
> create an exception, as they have a "n" argument of type int also :
> 
> LUA_API void  (lua_rawgeti) (lua_State *L, int idx, int n);
> LUA_API void  (lua_rawseti) (lua_State *L, int idx, int n);
> LUA_API void  (lua_createtable) (lua_State *L, int narr, int nrec);
> 
> These arguments should be of type size_t.
> First because a negative value does not make any sense.

Well, they work for negative values. (I agree it does not make much
sense).


> Second, because on 64-bit platforms, there is no reason to limit the
> size of tables to 2147483647 elements (provided you have plenty of
> memory...)

The size of tables is already limited to 2147483647 elements. Lua
internally uses 'int' to index all its arrays (except for strings/byte
arrays). It is a pain to work with unsigned values (such as size_t)
everywhere; ptrdiff_t has no garanties at all.


> And third, to be coherent with lua_rawlen, which returns a size_t value.

lua_rawlen returns size_t because its argument can be a string. For
tables, this value comes from an 'int' (luaH_getn) which comes from
several other 'int's.

-- Roberto