current line number in Lua

后端 未结 1 1424
无人及你
无人及你 2020-12-13 02:11

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

相关标签:
1条回答
  • 2020-12-13 02:37

    From Lua using debug.getinfo, e.g.,

    local line = debug.getinfo(1).currentline
    

    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

    0 讨论(0)
提交回复
热议问题