Help with your scripting

Helpful Debugging Code

Helpful Debugging Code

Postby Shando » 15 Feb 2016, 06:33

Hi All,

Whilst trying to debug one of my Plugins, I found that I really needed some automatic debugging ( rather than typing lprint statements everywhere ;) ), so I looked through a book that I bought a while ago ( "Beginning Lua Programming" by Kurt Jung & Aaron Brown - Wiley Publishing Inc, 2007 ) and came across the attached gem.

Basically, all you have to do is place the attached lua file in the relevant Skyline folder, and use the following commands:

Code: Select all
sky.include "calltrace.lua"
Trace ( ) -- Turns on tracing.
Untrace ( ) -- Turns off tracing.


The output is saved to a file in your Skyline Data folder as "Trace.txt".

IMPORTANT - as my modified code writes to a .txt file it is vital that you have an easy way of calling Untrace ( ) (e.g. just call Trace ( ) at the beginning of your block of code, and Untrace ( ) at the end). ALSO, multiple calls to Trace ( )/Untrace ( ) will overwrite the contents of the file, so best to ensure you only call it once for your block of code (use a Boolean to prevent multiple calls).

The output looks something like this, which may take a bit of getting used to, but it does mean you can analyse it in Excel etc.:

Code: Select all
calling Lua function from nowhere
   calling getCurrentIndex from Lua function ( line: 310 )
   returning from getCurrentIndex to Lua function ( line: 310 )
   calling getComboItemText from Lua function ( line: 310 )
   returning from getComboItemText to Lua function ( line: 310 )
   calling setTableItemText from Lua function ( line: 311 )
   returning from setTableItemText to Lua function ( line: 311 )
   calling getCurrentIndex from Lua function ( line: 313 )
   returning from getCurrentIndex to Lua function ( line: 313 )
   calling getComboItemText from Lua function ( line: 313 )
   returning from getComboItemText to Lua function ( line: 313 )
   calling setTableItemText from Lua function ( line: 314 )
   returning from setTableItemText to Lua function ( line: 314 )
   calling getValue from Lua function ( line: 316 )
   returning from getValue to Lua function ( line: 316 )
   calling toString from Lua function ( line: 317 )
   returning from toString to Lua function ( line: 317 )
   calling setTableItemText from Lua function ( line: 317 )
   returning from setTableItemText to Lua function ( line: 317 )
   calling setTableItemTextAlign from Lua function ( line: 319 )
   returning from setTableItemTextAlign to Lua function ( line: 319 )
   calling setTableItemTextAlign from Lua function ( line: 320 )
   returning from setTableItemTextAlign to Lua function ( line: 320 )
   calling setTableItemTextAlign from Lua function ( line: 321 )
   returning from setTableItemTextAlign to Lua function ( line: 321 )
   calling updateTable from Lua function ( line: 323 )
      calling getNumTableRows from updateTable ( line: 118 )
      returning from getNumTableRows to updateTable ( line: 118 )
      calling getTableItemText from updateTable ( line: 119 )
      returning from getTableItemText to updateTable ( line: 119 )
      calling getTableItemText from updateTable ( line: 120 )
      returning from getTableItemText to updateTable ( line: 120 )
      calling getTableItemText from updateTable ( line: 121 )
      returning from getTableItemText to updateTable ( line: 121 )
      calling insert from updateTable ( line: 124 )
      returning from insert to updateTable ( line: 124 )
      calling getTableItemText from updateTable ( line: 127 )
      returning from getTableItemText to updateTable ( line: 127 )
      calling getTableItemText from updateTable ( line: 128 )
      returning from getTableItemText to updateTable ( line: 128 )
      calling getTableItemText from updateTable ( line: 129 )
      returning from getTableItemText to updateTable ( line: 129 )
      calling populateCombos from updateTable ( line: 131 )
         calling getTableLength from populateCombos ( line: 257 )
            calling pairs from getTableLength ( line: 88 )
            returning from pairs to getTableLength ( line: 88 )
            calling (for generator) from getTableLength ( line: 88 )
            returning from (for generator) to getTableLength ( line: 88 )
            calling (for generator) from getTableLength ( line: 88 )
            returning from (for generator) to getTableLength ( line: 88 )
            calling (for generator) from getTableLength ( line: 88 )
            returning from (for generator) to getTableLength ( line: 88 )
            calling (for generator) from getTableLength ( line: 88 )
            returning from (for generator) to getTableLength ( line: 88 )
            calling (for generator) from getTableLength ( line: 88 )
            returning from (for generator) to getTableLength ( line: 88 )
         returning from getTableLength to populateCombos ( line: 257 )


Hope it helps some of you until the Devs find time to implement something in the Lua Editor.

Regards

Shando

PS: This will also show all standard Lua calls (for example "for generator" above). I haven't found an easy way to stop this as Lua treats all functions the same whether standard Lua or not :(
Attachments
calltrace.zip
(1.46 KiB) Downloaded 426 times
Ryzen 7 4800H 16GB GTX1650 Win 11 64
Love, Hope, Strength http://www.lovehopestrength.co.uk
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 560
Joined: 06 Mar 2013, 22:35
Location: Moffat Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: Helpful Debugging Code

Postby StarFire » 15 Feb 2016, 19:02

Many Thanks Shando, going to give this a try as it looks like it could save some time bug hunting :D
Dream the Journey, Live the Experience!
User avatar
StarFire
Skyline Founder
Skyline Founder
 
Posts: 1678
Joined: 03 Jan 2012, 18:50
Location: UK
Skill: Great creative
Skill: Programmer
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer

Re: Helpful Debugging Code

Postby SolarPortal » 15 Feb 2016, 19:33

Cool! Nice one! :D
Skyline Game Engine - Lead Dev.
Please provide as much info as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 4770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860

Twitter: @SolarPortal
Instagram: @SolarPortal
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Helpful Debugging Code

Postby CreativeOcclusion » 16 Feb 2016, 02:44

Thanks Shando...Much appreciated...
Thanks, CreativeOcclusion
User avatar
CreativeOcclusion
Skyline Warrior
 
Posts: 366
Joined: 22 Jun 2015, 19:34
Location: Texas

Re: Helpful Debugging Code

Postby Shando » 16 Feb 2016, 03:05

No worries :D

The output is a bit cluttered, but that's easily changeable in the calltrace.lua file.
Ryzen 7 4800H 16GB GTX1650 Win 11 64
Love, Hope, Strength http://www.lovehopestrength.co.uk
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 560
Joined: 06 Mar 2013, 22:35
Location: Moffat Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer


Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 6 guests

cron