lua-users home
lua-l archive

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



The more I think about it, the less I am convinced that looking
up object "names" in upvalues is useful. Maybe it is just my
programming style, but I think it would rarely give me useful
information, and it could well be misleading.

As I mentioned, the example provided originally won't work
because the calling stack frame is no longer available.
Even if it were not a tail call, though, the stack frame
might not be available, and if it were available it might
be no more than the name of a parameter to a function
with enclosing scope:

  fuction orderedList(comparator)
    ...
    function meta:__newindex(k, v)
      ...
      if comparator(t[k], t[i]) then ...
    end
  end

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 of the
line where the function error occurred. In fact, the file:line
information from the stack trace is generally adequate, so it
is only cosmetic to provide the function "name"; perhaps
the best solution would be a regex search of the source file.

However, :

> Quite the opposite.  We have plans for moving this whole "name
> guessing"
> stuff outside the Lua core into a library (at least the part that can
> be implemented with the debug API). In that way, the algorithm could be
> smarter and easier to change (e.g., it could look inside libraries to
> 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
currently unavailable.

The "names" table could also be exposed to Lua through interfaces such as
  obj = debug.name(obj, name)
and
  name = nameof(obj)
or something similar.

R.