lua-users home
lua-l archive

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


> Moreover, what is the exact relationship between a valid index and a pseudo index? The manual has its inconsistency:
> 
> 
> The manual says that a valid index refers to a real stack postition, whereas a pseudo index does not. So by definition they are totally different things. No pseudo index can be a valid index.
> 
> 
> But, in section 4.3:
> 
> 
> An acceptable index can be any valid index, including the pseudo-indices, but it also can be any positive index after the stack top within the space allocated for the stack, that is, indices up to the stack size.
> 
> The word "including" seems to indicate that pseudo-indices are included in valid index, which contradicts the definition.

You are right. I guess the best correction is to change the definition
of valid index.

The meaning of "valid index" in the code (see lapi.c) already includes
pseudo-indices. (It uses the term "stack index" for a valid index
that is not pseudo.) Among actual functions, only 'lua_rotate'
needs a valid index that excludes pseudo-indices. (lua_insert and
lua_remove both are macros using lua_rotate, and therefore have the same
restriction.)

Moreover, even in the manual the definition of "valid index" is already
dubious:

  A valid index is an index that refers to a real position within the
  stack, that is, its position lies between 1 and the stack top (1 ≤
  abs(index) ≤ top). Usually, functions that can modify the value at an
  index require valid indices.

The second sentence implies that valid indices are those that can be
modified, which would include pseudo-indices, too.

-- Roberto