[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: debug.getinfo(..).name is set/nil depending on subtle differences
- From: Tom Sutcliffe <tomsci@...>
- Date: Tue, 22 Dec 2020 19:07:55 +0000
> On 16 Dec 2020, at 11:52 am, Andrew Gierth <email@example.com> wrote:
> Lua function values don't have any "name" property inherent to the
> function; that is, the only "name" a function has is the name used to
> refer to some location from which the function value was fetched (so a
> function might have many names or none).
I must admit I've long wanted `function foo()` to store some sort of "declared name" property such that debug.getinfo would always return "foo", without all the magic funkyness of examining calling bytecode or module tables. I get that `function foo()` is merely a shorthand for `foo = function()`, and that logically there's no single name for a first-class function, but I'd be very much in favour of weakening that equivalence a little just to make debugging easier. While of course having the two syntaxes continue to otherwise behave identically at runtime.
I've ended up more than once in a situation with some dynamic dispatch logic that basically guaranteed the dynamically-dispatched function would never be named in stacktraces - to the point where I had a dynamically-generated helper function in debug builds just so that stacktraces would look friendlier. I don't have it to hand but it made the call through a named stack variable so the calling bytecode trick would find a name, and it was created with load() of a small string snippet. It would be nice not to have to go to such lengths!