[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sc-dev] Cocoa primitives
just getting back to this stuff.
i had this working fine earlier, tried to change one thing... and its
broken again.
i really can't figure out what little thing it is i'm supposed to do to
get the size
of the array set correctly.
it is again returning size 0
int prGetPathsDialog(struct VMGlobals *g, int numArgsPushed);
int prGetPathsDialog(struct VMGlobals *g, int numArgsPushed)
{
if (!g->canCallOS) return errCantCallOS;
PyrSlot *receiver = g->sp; // a cocoa
PyrSlot *array = g->sp - 1; // an array
NSDocumentController *docctl = [NSDocumentController
sharedDocumentController];
if (!docctl) {
NSLog(@"No NSDocumentController");
return errNone;
}
NSArray *urls = [docctl URLsFromRunningOpenPanel];
if(urls) {
int i;
int count = [urls count];
//NSLog(@"count %d",count);
// TODO: limit at max size of array
for (i = 0; i < count; i++)
{
PyrString* pyrPathString = newPyrString(g->gc,[[[urls
objectAtIndex: i ] path] cString],0,true);
PyrSlot slot;
SetObject(&slot, pyrPathString);
array->uo->slots[i].ucopy = slot.ucopy;
g->gc->GCWrite(array->uo,pyrPathString);
// have to set size field each time in order that gc
can find the created objects
array->uo->size = i+1;
}
// this says 1
//NSLog(@"array size: %d",array->uo->size);
}
return errNone;
}
but back in SC it is 0:
CocoaDialog {
classvar openDialogs;
var returnSlot;
*getPaths { arg okFunc,cancelFunc,
maxSize=20;
var new,returnSlot;
returnSlot = Array.new(maxSize);
new = super.newCopyArgs(returnSlot);
new.retainDialog;
{
new.prGetPathsDialog(returnSlot);
returnSlot.dump;
if(returnSlot.size > 0,{
okFunc.value(returnSlot);
},{
cancelFunc.value(returnSlot);
});
new.releaseDialog;
nil
}.defer;
^new
}
prGetPathsDialog { arg returnSlot;
_Cocoa_GetPathsDialog
^this.primitiveFailed
}
retainDialog {
openDialogs = openDialogs.add(this);
}
releaseDialog {
openDialogs.remove(this);
}
}
-felix