lua-users home
lua-l archive

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


> ~~~~~~~~~~~ Quote from section 3.4 ~~~~~~~~~~~ 
> 
> lua_type returns the type of a value in the stack, or LUA_TNONE for a
> non-valid index (that is, if that stack position is "empty").

> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The documentation should be more explicit here: lua_type returns
LUA_TNONE for any non-valid, *but acceptable*, index.


> So, some invalid indexes are rejected, others are treated as
> valid. That's not consistent.

Those that are treated as valid are exaclty the acceptable indices.
The manual states that "Most query functions accept as indices any value
inside the available stack space, [...]. Such indices are called
acceptable indices." "Note that 0 is never an acceptable index."



> Of course, if adding additional check for index being 0 is against
> certain policy, or is not compatible with older releases, then just
> forget about my question.

As already pointed out, the check is already there, you only need
to turn it on:

> static TObject *negindex (lua_State *L, int idx) {
>   if (idx > LUA_REGISTRYINDEX) {
>     api_check(L, idx != 0 && -idx <= L->top - L->base);    <<<<<!!!

Define api_check to be assert and go ahead.


> how can I find out value of "stackspace" that is used in check for
> validity of index?

It is not used for validity, but for acceptability.  You do not need to
ask for that value, because you set it: It is "the maximum stack size
you have set through lua_checkstack".

-- Roberto