Better stack traces

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
marco.r
Engineer
Engineer
Posts: 37
Joined: 16 Aug 2011 01:26

Better stack traces

Post by marco.r »

(Not sure if this is the right section)

I think that stack traces would be much more informative if for class instances, instead of just "INSTANCE" a string representation of the
class (i.e. the output of _tostring) would be printed.

I tried with the following quick hack, and it seems to do the job
(but I have zero experience with the squirrel VM so I'm not sure it is bug free :p)

Code: Select all


--- src/3rdparty/squirrel/sqstdlib/sqstdaux.cpp.orig	2011-10-09 15:01:53.000000000 +0200
+++ src/3rdparty/squirrel/sqstdlib/sqstdaux.cpp	2011-10-09 15:02:10.000000000 +0200
@@ -91,7 +91,10 @@
 					pf(v,_SC("[%s] CLASS\n"),name);
 					break;
 				case OT_INSTANCE:
-					pf(v,_SC("[%s] INSTANCE\n"),name);
+					sq_tostring(v,-1);
+					sq_getstring(v,-1,&s);
+					pf(v,_SC("[%s] %s\n"),name,s);
+					sq_poptop(v);
 					break;
 				case OT_WEAKREF:
 					pf(v,_SC("[%s] WEAKREF\n"),name);
Of course it needs more than this (e.g. what if the _tostring method throws an exception ?), but if there is interest I could make it more complete.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Better stack traces

Post by Zuu »

Looks good to me. No idea if there are any pit holes or cases where this will not work as I'm not familiar with the code that you have modified.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 7 guests