Get pointer address as string?

164 views
Skip to first unread message

Ian Beck

unread,
Aug 26, 2010, 12:53:02 PM8/26/10
to JSCocoa
Does anyone know how to take an object reference in Javascript, and
convert it to a string version of the object's pointer address?

Here's a simplified example of what I want to do

OBJECTIVE-C
[jsc callJSFunctionNamed:@"addressOfObject" withArguments:self, nil];

JAVASCRIPT
function addressOfObject(object) {
// Need to get pointer address as string from `object` here
}

Ian

Patrick Geiller

unread,
Aug 27, 2010, 2:38:00 AM8/27/10
to jsc...@googlegroups.com

How about an ObjC category method ?


@implementation NSObject (AddressAsString)
- (NSString*)addressAsString
{
return [NSString stringWithFormat:@"%llx", self];
}
@end


function addressOfObject(object) {
return object.addressAsString
}

-Patrick

Ian Beck

unread,
Aug 27, 2010, 3:05:06 PM8/27/10
to JSCocoa
Thanks, Patrick, that worked great!

Ian
Reply all
Reply to author
Forward
0 new messages