lua-users home
lua-l archive

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


I use the following function to have the line like. The comments are in the context of my library, but the code shall almost be what you need. Pil has a good introduction to the debug library (http://www.lua.org/pil/23.html).
‎

--- retrieve the file info for the ast node
-- this helps having meaningful error messages or assert in thecode
-- @tparam number upstack the depth of the stack between the user model and the
--                        rule procesing (generally 2)
-- @treturn string "filename":line
function dsl.where(upstack)
    local loc = debug.getinfo((upstack or 0)+1, "Sl")
    return string.format('"%s":%d', loc.short_src, loc.currentline)
end
‎
  Original Message  
From: Sean Conner
Sent: jeudi 15 mai 2014 23:33
To: Colin; Lua mailing list
Reply To: Lua mailing list


Also, is there an easy way to get the line number in Lua, much like C has
__LINE__? Because it would help me with error reporting with my C compiler
module [1][2].

-spc

[1]	https://github.com/spc476/lua-conmanorg/blob/master/lua/cc.lua

[2]	Which relies upon the wrapper for TCC:
https://github.com/spc476/lua-conmanorg/blob/master/src/tcc.c