lua-users home
lua-l archive

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



> On 16 Dec 2020, at 11:52 am, Andrew Gierth <andrew@tao11.riddles.org.uk> 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!

Cheers,

Tom