0

Possible Duplicate:
current line number in Lua

Is it possible, for say, to find the line that called a specified function?

Community
  • 1
  • 1
John
  • 1

4 Answers4

4

This seems to have been answered here: current line number in Lua

Community
  • 1
  • 1
foobuzz
  • 75
  • 7
0

Not Lua specific, but if you know what function it is, you can place a debug message before it gets called.

There may be some kind of debugging that's Lua specific that I'm unaware of.

sample

before:

myFunc(param1);
myFunc(param2);
myFunc(param3);

after:

io.write("About to call myFunc the first time");
myFunc(param1);
io.write("About to call myFunc the second time");
myFunc(param2);
io.write("About to call myFunc the third time");
myFunc(param3);

Obviously you can use more meaningful debug messages than that.

corsiKa
  • 81,495
  • 25
  • 153
  • 204
0

You can try print(debug.traceback()), this will give you the stack to where you call it. From there you could find the function that called you and what line it was.

sylvanaar
  • 8,096
  • 37
  • 59
0

The proper way would be to use the debug library's getinfo, using the level 2:

line_of_caller = debug.getinfo(2,"l").currentline
daurnimator
  • 4,091
  • 18
  • 34