Lua中的当前行号

Lua 是否支持类似于 C 语言中的 __LINE__ 宏,用于返回当前代码行数?我知道 Lua 有一个称为 _G 的特殊内置变量,但在其中我看不到行号信息...

原文链接 https://stackoverflow.com/questions/2555856

点赞
stackoverflow用户285151
stackoverflow用户285151

从 Lua 使用 debug.getinfo,例如:

local line = debug.getinfo(1).currentline

从 C 使用 lua_getinfo(这将返回 Lua 代码中的行号):

lua_Debug ar;
lua_getstack(L, 1, &ar);
lua_getinfo(L, "nSl", &ar);
int line = ar.currentline

http://www.lua.org/manual/5.1/manual.html#lua_getinfo

http://www.lua.org/manual/5.1/manual.html#pdf-debug.getinfo

2010-03-31 19:29:06