lua-users home
lua-l archive

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


Consider the following:

function foo ()
  function bar () end
end

Is there a precise way, at runtime, to find the function that encloses bar?

It appears the best (but imprecise) approximation is to use
debug.getinfo() and then compare the values of linedefined and
lastlinedefined for each function.

(This approximation would be incorrect (or inconclusive) in the
(possibly rare) circumstance where two functions were completely
defined on the same line(s).)