[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Using debug to find the enclosing function
- From: Parke <parke.nexus@...>
- Date: Tue, 8 Dec 2020 11:45:02 -0800
Consider the following:
function foo ()
function bar () 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).)