lua-users home
lua-l archive

Re: Gets function name from the stack

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


If you want the name the function was called with, here's how Lua gets
it (and how you get those really nice argument error messages in C):
/* UNTESTED */
 lua_Debug ar;
 if (!lua_getstack(L, 0, &ar)) /* no stack frame? */
 ar.name = "?"; /* Some default ? */
 else
 {
 lua_getinfo(L, "n", &ar);
 if (ar.name == NULL)
 ar.name = "?"; /* <-- PUT DEFAULT HERE */
 }
I think this is slow though? So perhaps you may want to avoid it
unless it is really necessary...
Hope that helps,
-- 
-Patrick Donnelly
"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."
-Will Durant

AltStyle によって変換されたページ (->オリジナル) /