Jump to content

Debug Callstack/Trace/Globals Library


TylerH
 Share

Recommended Posts

File Name: Debug Callstack/Trace/Globals Library

File Submitter: TylerH

File Submitted: 09 Dec 2009

File Category: Lua Scripts

 

This is a simple add-on library I coded based on the Lua debug library and some example code in the Programming In Lua book.

 

It features:

  • Trace
  • Traceback
  • PrintGlobals
  • LogGlobals

Trace will run a trace from the point in code debug.Trace() is called up to the top of the stack. This is basically a call stack, and produces output like so:

Trace: 

1: Line 26	"Trace"	Scripts/debug.lua

2: Line 40	"GetImpactDecal"	scripts/classes/bullet.lua

3: Line 151	"UpdateBullets"	scripts/classes/bullet.lua

4: Line 388	"N/A"	[string "dofile("Scripts/constants/collision_const.l..."]

 

It will even trace into C functions, area of code with no function (i.e. the "N/A" you see), and through multiple files (compiled bytecode or normal).

 

Traceback is simply Lua's default implementation, except I print it out and log it in AppLog.

 

PrintGlobals will print the key names of everything in the _G table, this includes all of the entities, Leadwerks functions, things you don't know of, etc.

 

LogGlobals does the same as print globals, but prints to the AppLog and not the Console.

 

 

To use this simply call dofile("Scripts/debug.lua") in any of your Lua files (be it entity, game, etc.)

 

It is rather useful for tracing where errors occur more quickly than Lua error messages do.

 

Click here to download this file

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...