Is my understanding correct that lua_getinfo(L,"n",&ar) does not look
at the previous stack frame's upvalues when guessing a "name" for the
function?
Yes.
If so, is there any reason why not?
No, besides some extra complexity.
My workaround for this will be to query the calling 'ar' myself and
search the named upvals (if getinfo fails to find the name through the
normal mechanism). Is there any reason why this is a bad idea?
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.)
-- Roberto