Created
April 11, 2009 23:25
-
-
Save nilium/93779 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Last login: Tue Apr 7 02:56:43 on ttys002 | |
/Users/noel/Source/Misc/bmax/lua-reflection/test ; exit; | |
[noel@Ouroboros ~]$ /Users/noel/Source/Misc/bmax/lua-reflection/test ; exit; | |
~>Unhandled Exception:Not handling this shit | |
~> | |
t | |
~>StackTrace{ | |
~>@/Users/noel/Source/Misc/bmax/lua-reflection/test.bmx<26,1> | |
~>Function test | |
~>Global Running:Int=1 | |
~>Local lvm:Byte Ptr=$003a1e80 | |
~>@/Users/noel/Source/Misc/bmax/lua-reflection/lua-reflection.bmx<817,2> | |
~>Function lua_implementtypes | |
~>Local state:Byte Ptr=$003a1e80 | |
~>Local typeIter:TTypeId=$002d3e60 | |
~>@/Users/noel/Source/Misc/bmax/lua-reflection/lua-reflection.bmx<818,3> | |
~>Local <local> | |
~>@/Users/noel/Source/Misc/bmax/lua-reflection/lua-reflection.bmx<782,2> | |
~>Function lua_implementtype | |
~>Local state:Byte Ptr=$003a1e80 | |
~>Local from:TTypeId=$002d3e60 | |
~>Local expose:Int=1 | |
~>Local static:Int=1 | |
~>Local noclass:Int=1 | |
~>Local hidefields:Int=0 | |
~>@/Users/noel/Source/Misc/bmax/lua-reflection/lua-reflection.bmx<783,3> | |
~>Local <local> | |
~>@/Users/noel/Source/Misc/bmax/lua-reflection/lua-reflection.bmx<784,4> | |
~>Local <local> | |
~>@/Users/noel/Source/Misc/bmax/lua-reflection/lua-reflection.bmx<785,5> | |
~>Local <local> | |
~>@/Users/noel/Source/Misc/bmax/lua-reflection/lua-reflection.bmx<554,2> | |
~>Function LREF_PushBMaxObject | |
~>Local state:Byte Ptr=$003a1e80 | |
~>Local obj:Object=$17ae5630 | |
~>Local from:TTypeId=$002d3e60 | |
~>Local expose:Int=1 | |
~>Local static:Int=1 | |
~>Local noclass:Int=1 | |
~>Local hidefields:Int=0 | |
~>Local objidx:Int=1 | |
~>Local methIter:TMethod=Null | |
~>Local tableIdx:Int=0 | |
~>Local rename:String="" | |
~>Local name:String="" | |
~>Local ownObjIdx:Int=1 | |
~>@/Users/noel/Source/Misc/bmax/lua-reflection/lua-reflection.bmx<559,3> | |
~>Local <local> | |
~>@/Users/noel/Source/Misc/bmax/lua-reflection/lua-reflection.bmx<132,2> | |
~>Function LREF_AttachMetatable | |
~>Local state:Byte Ptr=$003a1e80 | |
~>Local idx:Int=1 | |
~>Local metatable:String="LREF_metatable_objects" | |
~>@/Users/noel/Source/Misc/bmax/lua-reflection/lua-reflection.bmx<133,3> | |
~>Local <local> | |
~>} | |
~> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Cocoa/Cocoa.h> | |
static NSCharacterSet* emptySet = nil; | |
static void scanScopedString(NSString* input) { | |
NSAutoreleasePool *pool = [NSAutoreleasePool new]; | |
NSScanner* scanner = [NSScanner scannerWithString:input]; | |
NSString* scope = nil; | |
if ( [scanner scanUpToString:@" " intoString:&scope] ) | |
{ | |
NSLog(@"Scope: %@", scope); | |
NSString* name = nil; | |
if ( [scope compare:@"Function"] == NSOrderedSame || [scope compare:@"Method"] == NSOrderedSame ) | |
{ | |
NSString* methodName = nil; | |
if ( [scanner scanUpToCharactersFromSet:emptySet intoString:&methodName] ) | |
NSLog(@"Open %@: %@", scope, methodName); | |
else | |
NSLog(@"Error reading function/method name"); | |
} | |
else if ( [scope compare:@"Local"] == NSOrderedSame && [scanner scanString:@"<local>" intoString:NULL] ) | |
{ | |
NSLog(@"Local stack frame"); | |
} | |
else if ( ( [scope compare:@"Local"] == NSOrderedSame || [scope compare:@"Global"] == NSOrderedSame ) && | |
[scanner scanUpToString:@":" intoString:&name] ) | |
{ | |
NSLog(@"Name: %@", name); | |
[scanner scanString:@":" intoString:NULL]; | |
NSString* type = nil; | |
[scanner scanUpToString:@"=" intoString:&type]; | |
NSLog(@"Type: %@", type); | |
[scanner scanString:@"=" intoString:NULL]; | |
if ( [scanner scanString:@"$" intoString:NULL] ) | |
{ | |
unsigned long long address = 0LL; | |
[scanner scanHexLongLong:&address]; | |
if ( address & 0xFFFFFFFF00000000LL ) | |
NSLog(@"Address: 0x%.16lX", address); | |
else | |
NSLog(@"Address: 0x%.8lX", address); | |
} | |
else | |
{ | |
if ( [type compare:@"Int"] == NSOrderedSame || [type compare:@"Short"] == NSOrderedSame || [type compare:@"Byte"] == NSOrderedSame ) | |
{ | |
int value = 0; | |
[scanner scanInt:&value]; | |
NSLog(@"Value: %i", value); | |
} | |
else if ( [type compare:@"Long"] == NSOrderedSame ) | |
{ | |
long long value = 0LL; | |
[scanner scanLongLong:&value]; | |
NSLog(@"Value: %li", value); | |
} | |
else if ( [type compare:@"Float"] == NSOrderedSame ) | |
{ | |
float value = 0.0f; | |
[scanner scanFloat:&value]; | |
NSLog(@"Value: %f", value); | |
} | |
else if ( [type compare:@"Double"] == NSOrderedSame ) | |
{ | |
double value = 0.0; | |
[scanner scanDouble:&value]; | |
NSLog(@"Value: %Lf", value); | |
} | |
else | |
{ | |
NSString* value = nil; | |
if ( [scanner scanUpToCharactersFromSet:emptySet intoString:&value] ) | |
{ | |
NSLog(@"Value: %@", value); | |
} | |
} | |
} | |
} | |
} | |
[pool drain]; | |
} | |
static void scanString(NSString* input) { | |
NSAutoreleasePool *pool = [NSAutoreleasePool new]; | |
if ( ![input hasPrefix:@"~>"] || [input length] == 2 ) | |
{ | |
[pool drain]; | |
return; | |
} | |
NSScanner* scanner = [NSScanner scannerWithString:[input substringFromIndex:2]]; | |
if ( [scanner scanString:@"StackTrace{" intoString:NULL] ) | |
{ | |
NSLog(@"Beginning of stack trace"); | |
} | |
else if ( [scanner scanString:@"}" intoString:NULL] ) | |
{ | |
NSLog(@"End of stack trace"); | |
} | |
else if ( [scanner scanString:@"@" intoString:NULL] ) | |
{ | |
// @/Path/To/Source/File.bmx<line,col> | |
NSString* path = nil; | |
int line = 0; | |
int column = 0; | |
if ( [scanner scanUpToString:@"<" intoString:&path] ) | |
{ | |
NSURL* fileURL = [NSURL fileURLWithPath:path]; | |
[scanner scanString:@"<" intoString:NULL]; | |
[scanner scanInt:&line]; | |
[scanner scanString:@"," intoString:NULL]; | |
[scanner scanInt:&column]; | |
NSLog(@"Scope for %@ on line %i, column %i", fileURL, line, column); | |
} | |
} | |
else if ( [scanner scanString:@"Unhandled Exception:" intoString:NULL] ) | |
{ | |
NSString* exceptionMessage = nil; | |
if ( [scanner scanUpToCharactersFromSet:emptySet intoString:&exceptionMessage] ) | |
NSLog(@"Unhandled exception found: %@", exceptionMessage); | |
else | |
NSLog(@"Error reading unhandled exception message"); | |
} | |
else | |
{ | |
if ( [scanner scanUpToCharactersFromSet:emptySet intoString:&input] ) | |
scanScopedString(input); | |
else | |
NSLog(@"FAILED TO READ STRING: %@", input); | |
} | |
[pool drain]; | |
} | |
int main( int argc, char ** argv ) { | |
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; | |
emptySet = [NSCharacterSet characterSetWithCharactersInString:@""]; | |
NSCharacterSet* wpnlSet = [NSCharacterSet whitespaceAndNewlineCharacterSet]; | |
if ( argc == 1 ) { | |
char line[256]; | |
while ( fgets(line, 256, stdin) ) { | |
scanString( [[NSString stringWithUTF8String:line] stringByTrimmingCharactersInSet:wpnlSet] ); | |
NSLog(@" "); | |
} | |
} | |
else | |
{ | |
for ( int i = 2; i < argc; ++i ) | |
scanString([NSString stringWithUTF8String:argv[i]]); | |
} | |
[pool drain]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment