lua-users home
lua-l archive

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


There seems to be a mismatch between the documentation and the code of lua_setlocal:

The doc says:
> Returns NULL (and pops nothing) when the index is greater than the number of active local variables.

The code always pops the top of the stack:

LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
  StkId pos = 0;  /* to avoid warnings */
  const char *name = findlocal(L, ar->i_ci, n, &pos);
  lua_lock(L);
  if (name)
    setobjs2s(L, pos, L->top - 1);
  L->top--;  /* pop value */
  lua_unlock(L);
  return name;
}

IMO, the correct behavior is the one in the doc  (consistent with lua_getlocal).
Actually, I found this in Lua 5.2, but this part of code and doc is exactly the same in Lua 5.3.0 rc2.

Another doc thing about debug function lua_getlocal: 
it would be helpful to add a sentence in the reference manual about the order in which local variables are returned. The sentence in PIL page 239 would be just good: "Lua numbers local variables in the order that they appear in a function, counting only the variables that are active in the current scope of the function ».
Writers of debug utilities may need to known this order is needed when several locals with the same name are active in the current scope, to know which one is masking the others...

Hope this helps

Jean-Luc

> Le 22 déc. 2014 à 15:34, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> a écrit :
> 
> Lua 5.3.0 (rc2) is now available for testing at
> 	http://www.lua.org/work/lua-5.3.0-rc2.tar.gz
> 
> MD5	61726271cf342794909a1752ea0c0aae  -
> SHA1	457be7b889f7825c3b9c8b9a4b95b85c0c0b434d  -
> 
> This is a release candidate for the final release of Lua 5.3.0.
> 
> A few things have changed since beta that we'd like to test in the wild.
> In particular, we made some changes in luaconf.h and in the Makefile
> that we'd like to test. Please try compiling the current code in as many
> platforms as possible. We expect the compilation will go smoothly as usual
> but please report any warnings or other glitches.
> 
> We'd also like feedback on the documentation:
> 	http://www.lua.org/work/doc/readme.html
> 	http://www.lua.org/work/doc/contents.html
> 	http://www.lua.org/work/doc/manual.html
> 
> Finally, for those of you into this, please test luac -l -l on your
> scripts, just to make sure we haven't missed anything with the new
> VM instructions etc.
> 
> The main change in Lua 5.3.0 is the introduction of integers. See also
> 	http://www.lua.org/work/doc/#changes
> 
> The complete diffs are available at
> 	http://www.lua.org/work/diffs-lua-5.3.0-rc1-rc2.txt
> 
> An updated test suite is available at
> 	http://www.lua.org/work/lua-5.3.0-rc2-tests.tar.gz
> 
> All feedback welcome. Thanks.
> --lhf
> 
>