I really like C's __LINE__开发者_运维百科
and __FILE__
... does lua provide something similar? (I find it useful for tracking down printf's ... to know which file and which line the message comes from).
Thanks!
function __FILE__() return debug.getinfo(2,'S').source end
function __LINE__() return debug.getinfo(2, 'l').currentline end
Untested, credit goes here.
I use something like this for getting the line number from the c side:
int lua_getline(lua_State* L, int level) {
lua_Debug ar;
lua_getstack(L, level, &ar);
lua_getinfo(L, "l", &ar);
return ar.currentline;
}
Calling lua_getinfo with "lS" will fill the source field of the lua_Debug struct although it may not always be a file name IIRC.
精彩评论