lua-users home
lua-l archive

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


On Mon, May 03, 2004 at 04:45:48PM -0300, Roberto Ierusalimschy wrote:
> > ~~~~~~~~~~~ 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.

:) Yep. Probably the documentation then should be even more explicit and
state that if the index is not acceptable then behaviour is undefined.

[...]

> > 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.

Please add this to the documentation as well. Reading sources is
good practice, but not always things can be figured out very quickly.

> 
> 
> > 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".

Hm. Docs say that lua_checkstack "never shrinks the stack", which means
that the stack can be bigger than the number I've used in the call to
lua_checkstack, so acceptable indices are not necessarily limited by the
value I have set ;-) Well, this is teasing really. I understand already,
that I should simply set api_check and let it do necessary checks, and
never bother with those checks myself.

Thank you for the answers. They were helpful.

Andrei