Proper syntax for pass-by-reference items

6 views
Skip to first unread message

Ian Beck

unread,
Aug 27, 2010, 5:39:45 PM8/27/10
to JSCocoa
I'm trying to convert this Objective-C to Javascript:

BOOL exists;
BOOL isDirectory;
exists = [[NSFileManager defaultManager] fileExistsAtPath:path
isDirectory:&isDirectory];

A straight conversion with no extra stuff to handle the pass-by-
reference fails:

var exists, isDirectory;
exists =
NSFileManager.defaultManager.fileExistsAtPath_isDirectory_(path,
isDirectory);
// Result is something like exists == 1, isDirectory == undefined

I went through the tests, but the examples didn't make it clear to me
how to handle this kind of scenario. How should I go about calling
this kind of function that needs something passed by reference? Also,
are there any differences between the example above and passing a
pointer to a pointer (methods that take an NSError** for instance)?

Ian

Ian Beck

unread,
Aug 27, 2010, 5:47:57 PM8/27/10
to JSCocoa
D'oh! Right after I posted this, I went back to take another troll
through the test just in case and discovered the answer to my
problem. It's in Test #27 for anyone else interested, and basically
looks like this for the example above:

var exists;
var isDirectory = new outArgument;
exists =
NSFileManager.defaultManager.fileExistsAtPath_isDirectory_(path,
isDirectory);
// Result is something like exists == 1, isDirectory == 0

I haven't tried this with something like an NSError** argument, but
hopefully that will function the same.

Ian
Reply all
Reply to author
Forward
0 new messages