Lua当前行号 [英] current line number in Lua
本文介绍了Lua当前行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Lua是否支持类似于C的__LINE__
宏(该宏返回当前代码行的编号)?我知道Lua有一个名为_G
的特殊内置变量,但是我看不到那里的行号...
Does Lua support something like C's __LINE__
macro, which returns the number of the current code line? I know Lua has a special built-in variable called _G
, but I don't see line number in there...
推荐答案
从Lua使用debug.getinfo,例如
From Lua using debug.getinfo, e.g.,
local line = debug.getinfo(1).currentline
从C使用lua_getinfo(这将返回lua代码中的行号)
From C using lua_getinfo (This will return the linenumber inside lua code)
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
这篇关于Lua当前行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文