[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: lua_getinfo(L,"n",&ar) doesn't use upvals to guess function name?
- From: RLake@...
- Date: Fri, 19 Mar 2004 18:00:47 -0500
The more I think about it, the less I am convinced
up object "names" in upvalues is useful.
Maybe it is just my
programming style, but I think it would rarely give
information, and it could well be misleading.
As I mentioned, the example provided originally won't
because the calling stack frame is no longer available.
Even if it were not a tail call, though, the stack
might not be available, and if it were available it
be no more than the name of a parameter to a function
with enclosing scope:
function meta:__newindex(k, v)
if comparator(t[k], t[i]) then
The fact that the function which blew up had the upvalue
"name" "comparator" would be of
very little interest, since
that would be immediately obvious from examination
line where the function error occurred. In fact, the
information from the stack trace is generally adequate,
is only cosmetic to provide the function "name";
the best solution would be a regex search of the source
> Quite the opposite. We have plans for moving
this whole "name
> stuff outside the Lua core into a library (at least the part that
> be implemented with the debug API). In that way, the algorithm could
> smarter and easier to change (e.g., it could look inside libraries
> find names like "math.sin", could look for upvalues, etc.)
That seems very useful. For what it is worth, my suggestion
would be to
provide the "names" table which I implemented
in my last email on this
subject in roughly the same way the "n"
table is implemented, as a library
table. This would allow me (us) to register the name
of a C function,
possibly even with a (debugging) version of luaL_openlib,
which is a facility
The "names" table could also be exposed
to Lua through interfaces such as
obj = debug.name(obj, name)
name = nameof(obj)
or something similar.