lua-users home
lua-l archive

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


On Sat, Jul 3, 2010 at 3:30 AM, HyperHacker <hyperhacker@gmail.com> wrote:
> I've written a function that performs variable substitution in strings
> (e.g. replacing "$foo" with value of foo). The only way I could find
> for it to access the local variables of its caller is to use
> debug.getlocal...
On Wed, Jul 7, 2010 at 9:05 AM, GrayFace <sergroj@mail.ru> wrote:
> Why? The old behavior seems more logical. Now we would have to worry about
> tail calls when we pass a stack level to 'error' function?

I've argued in the past that the `level` parameter on `error` was
problematic in itself [1] and that there's no really good way to do
string interpolation [2], with the best solution possibly being Lua
supporting some lexical or preprocessor step that transforms printf
"${x},${y},${x}" into printf("${x},${y},${x}", x, y, x), which would
then allow functions like `printf` to complete the implementation of
interpolation as they see fit.

The point I'm making is that if better solutions to these problems
were available that avoid stack levels (like the recent replacement of
setfenv/getfenv with _ENV), then the question of whether stack level
distances are preserved may become moot.

[1] http://lua-users.org/lists/lua-l/2010-01/msg01255.html
[2] http://lua-users.org/lists/lua-l/2010-07/msg00105.html