lua-users home
lua-l archive

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

On 26/08/2011 12.54, Axel Kittenberger wrote:
The manual doesn't say that non-acceptable indices should return NULL.

In my opinion it does.

"If the value at the given acceptable index is a full userdata,
returns its block address. If the value is a light userdata, returns
its pointer. Otherwise, returns NULL"

This english compiles into pseudo-code

if valid(index) and valueat(index) == userdata then return block address
elseif valid(index) and valueat(index) == light userdata then return pointer
else return NULL.

So an invalid index returns NULL.

Sadly (for computer manuals writers, not for poets) natural languages can be ambiguous, so Josh has a point in saying that valid(index) may be a precondition, so the whole lot may also be pseudocoded as:

if valid(index) then
  if valueat(index) == userdata then return block end
  elseif valueat(index) == lightuserdata then return pointer end
  else return NULL end
 undefined behaviour

From a natural language POV the interpretation may be correct as well, especially if you interpret it in the context of the whole manual and not in isolation (another "feature" of natural languages - they don't have to stick only to locally declared information).

Of course the debate may well indicate that a more clear formulation would be helpful, since it is a refman and not a poetry text (to keep with the former analogy).

-- Lorenzo