lua-users home
lua-l archive

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


On 1/28/08, Mike Pall <mikelu-0801@mike.de> wrote:
> E. Wing wrote:
> > Since these were only triggered on error conditions, debug.getinfo
> > would only be called in limited situations (basically for the exact
> > purpose of debugging) so performance was not an issue.
>
> To get the Lua 5.0 behaviour use this:
>
>   local function findglobal(f)
>     for k,v in pairs(_G) do
>       if v == f then return k end
>     end
>   end
>
>   ...
>   local info = debug.getinfo(level, "nSlf")
>   local name = info.name or findglobal(info.func)
>   ...
>   print(name)
>
> --Mike

Thank you again for the response. That was really helpful. Is there a
C-API equivalent to this? My real code base has been accessing the
lua_Debug info from the C-side to do all the error/debugging handling
to make things transparent to the scripting side. It turns out that
calling back into to Lua during my error handling to get this
debugging info is awkward due to the way things are currently
designed. My error system had minimal dependencies and assumptions on
non-out-of-the-box stuff, but now I have to make sure I have the above
debug functions defined and an agreement on the function name entry
point.

Thanks,
Eric