[erlang-questions] How to get the line number of current executable code?

Kevin Scaldeferri kevin@REDACTED
Fri Aug 15 22:35:45 CEST 2008


Many languages are compiled to byte code, but able to recover line  
numbers at run time.  I assume they annotate the byte codes with file  
and line information.  Note that this is more powerful than the Erlang  
macros.  For example, Perl's caller() function allows you to inspect  
the full call stack in this way.


-kevin


On Aug 15, 2008, at 12:07 PM, Matt Williamson wrote:

> You should trust the macro. It must use a similar method to Python's  
> because they are both compiled to bytecode and thus there wouldn't  
> *really* be line numbers in either one.
>
> 2008/8/15 devdoer bird <devdoer2@REDACTED>
> Thanks.
>
> How can I do this without macro? I know python supply some tools to  
> determine the line number in run time,like inspect module.
>
>
> 2008/8/16, Anders Nygren <anders.nygren@REDACTED>:
> 2008/8/15 devdoer bird <devdoer2@REDACTED>:
> > HI:
> >
> > I want to implement a function like "get_current_lineno()/0" to  
> get the
> > current line number of the calling point?
> > Eg.
> > .....
> > ....
> > io:format("current line is ~w\n",[get_current_lineno()])
> > .....
> >
> > the above code will print the line number of the calling point in  
> the source
> > file.
> >
> > How can I do this  in erlang?
>
> There is a predefined macro ?LINE that does that
> so
> io:format("current line is ~w\n",[?LINE])
>
> /Anders
>
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://www.erlang.org/mailman/listinfo/erlang-questions
> >
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list