Possible Duplicate:
current line number in Lua
Is it possible, for say, to find the line that called a specified function?
Possible Duplicate:
current line number in Lua
Is it possible, for say, to find the line that called a specified function?
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.
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.
The proper way would be to use the debug library's getinfo, using the level 2
:
line_of_caller = debug.getinfo(2,"l").currentline