Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

automatically tracing the location of a function call
Started by sporkfin Jan 03 2020 08:46 AM

- - - - -
2 replies to this topic

Best Answer XeduR @Spyric , 03 January 2020 - 09:10 AM

I could remember this wrong, or understand your question wrong, but you might be able to get by with debug.traceback()(see https://www.lua.org/pil/8.5.html).

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 711 posts
  • Corona SDK

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?



[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,103 posts
  • Corona SDK

  Best Answer

I could remember this wrong, or understand your question wrong, but you might be able to get by with debug.traceback()(see https://www.lua.org/pil/8.5.html).


  • pixec likes this

[TOPIC: post.html]
#3

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 711 posts
  • Corona SDK

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!

print(debug.traceback())

 

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.




[topic_controls]
[/topic_controls]