Search code examples
lua

lua equiv of __LINE__ and __FILE__?


I really like C's __LINE__ and __FILE__ ... does lua provide something similar? (I find it useful for tracking down printf's ... to know which file and which line the message comes from).

Thanks!


Solution

  • function __FILE__() return debug.getinfo(2,'S').source end
    function __LINE__() return debug.getinfo(2, 'l').currentline end
    

    Untested, credit goes here.