lua-users home
lua-l archive

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


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 in a loop, looking at each variable at each level, then
the global table, before giving up. This isn't terribly efficient, but
it's worked for a while.

However, the other day, it started giving me problems. It seems that
after a while, debug.getlocal stops returning useful information for
some levels. Specifically, at levels 2 to 5, it returns nil for the
variables' names and values. Beyond level 5 it still manages to
retrieve correct information.

Is this defined behaviour? Is there a better way to access the calling
function's environment to look up its local variables by name?

-- 
Sent from my toaster.