[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-dev] writing primitives

On Monday, November 25, 2002, at 07:41 PM, James McCartney wrote:

When you do fill in slots in an object with other objects, you must call g->gc->GCWrite(obj, slot) in order to notify the garbage collector that you have modified a slot that it may have already scanned.

i'm still doing something wrong. g->gc->GCWrite is being accused of being a struct. source/app/CocoaFilePrimitives.M:96: invalid use of undefined type `struct GC' /Volumes/Macintosh HD/Users/cruxxial/SuperCollider3/headers/lang/VMGlobals.h:55: forward declaration of `struct GC'

NSString* pyrSlotToNSString(PyrSlot *slot)
    PyrString* pyrString = slot->uos;
return [NSString stringWithCString: pyrString->s length: pyrString->size];

int prGetPathsDialog(struct VMGlobals *g, int numArgsPushed);
int prGetPathsDialog(struct VMGlobals *g, int numArgsPushed)
        if (!g->canCallOS) return errCantCallOS;

        PyrSlot *receiver = g->sp - 2;
        PyrSlot *defaultPath = g->sp - 1;
	PyrSlot *prompt = g->sp;

        NSLog(@"numArgsPushed %d g->sp %d",numArgsPushed,g->sp);

        // check arg types
        if (!isKindOfSlot(defaultPath, class_string)) {
                return errWrongType;
        if (!isKindOfSlot(prompt, class_string)) {
                return errWrongType;

        NSString* nsDefaultPath = pyrSlotToNSString(defaultPath);
        NSString* nsPrompt = pyrSlotToNSString(prompt);

        NSLog(@"defpath %@ prompt %@",nsDefaultPath,nsPrompt);

NSDocumentController *docctl = [NSDocumentController sharedDocumentController];
        if (!docctl) {
            post("No NSDocumentController\n");
            return errFailed;

        // if default path not nil, locate to there

        // prompt
        NSArray *urls =  [docctl URLsFromRunningOpenPanel];

        // if cancelled, return nil
        if(!urls) {
            return errNone;
        } else {
            NSString *nspath;
            int i;
            int count = [urls count];
            // array to return
PyrObject *scArray = (PyrObject*)instantiateObject(g->gc, class_array, count, false, true);

            for (i = 0; i < count; i++)
                nspath = [[urls objectAtIndex: i ] path];
                NSLog (@"Object at index %d is: %@", i, nspath);
PyrString* pyrPathString = newPyrString(g->gc,[nspath cString],false,true);
                PyrSlot *slot;
                putIndexedSlot(g ,scArray,slot  ,count);
            // delete objects ?
            return errNone;

also learn me some about what to delete or what not to create.