How to see which line a function was called in?

The title says it all. Can someone help me with this? Thanks!

function hi()
   —What do I do to see that it was called in line 5?
end

hi() --line 5

I dont know if this is possible but could be by using script.Source. Thats my only guess at least. It might only be useable with plugins though so depending on the reasons you want to do this it may vary

function hi()
   local lineWasCalledFrom = debug.info(2, 'l')
   print("Called from line:", lineWasCalledFrom)
end

hi()
4 Likes