automatically tracing the location of a function call

I’m not even sure how to phrase this but basically I add origin tags to my function call parameters. 

In the example below I create an object from a function named “newObject” in the module “create_objects.lua” and then set it’s color with a setColor( ) function in my “color.lua” module, thus —> color.setColor( ).

I use the “origin” parameter to track the origin of the setColor( ) function - in this case so I know it came from the “objects” module and not the “enemy” module.


color.setColor( object1, {color = “red”, origin = “newObject( ) ; create_object.lua”)


I started doing this to help with debugging years ago (a sort of Jerry-rigged stack trace) and now it’s a habit but, hey, there’s got to be a better way.  Any Lua gurus want to chime in?

I could remember this wrong, or understand your question wrong, but you might be able to get by with debug.traceback()(see

Yes, that is exactly what I need!  It’s hard to do a google search without the proper terms!  The “origin” method is still useful in some situations but print(debug.traceback()) gives me exactly what I am looking for, right not today - Thanks!




I can’t believe I never used this before.  I thought I had to mess with lua-pcall to get this info but I see from the reading you pointed me to that the pcall approach was doomed to fail for the what I was looking for.