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

Re: [MacPerl] Mac::Glue to CodeWarrior IDE?



>Chris Nandor pudge@pobox.com wrote:

First off, let me thank you for the quick help...

> Are you sure it is not supposed to be a one-element list?  Maybe that is
> what CodeWarrior is supposed to return?  Try doing it in AppleScript.


Applescript:
    set docobj to document named "foo.mcp"
    set targs to every target of docobj
Result:

{
    target "MacOS Toolbox PPC Debug" of project document 1 of application
"CodeWarrior IDE 4.1",
    target "MacOS Toolbox Carbon Debug" of project document 1 of application
"CodeWarrior IDE 4.1",
    target "MacOS Toolbox PPC Final" of project document 1 of application
"CodeWarrior IDE 4.1",
    target "MacOS Toolbox Carbon Final" of project document 1 of application
"CodeWarrior IDE 4.1"
}

or as AEPrint from Script Debugger:

[
    obj {
        form:name, 
        want:type(TRGT),
        seld:³MacOS Toolbox PPC Debug²,
        from:obj {
            form:indx,
            want:type(PRJD),
            seld:1,
            from:'null'()
        }
    }, 
    obj {
        form:name, 
        want:type(TRGT),
        seld:³MacOS Toolbox Carbon Debug²,
        from:obj {
            form:indx,
            want:type(PRJD),
            seld:1,
            from:'null'()
        }
    }, 
    obj {
        form:name, 
        want:type(TRGT),
        seld:³MacOS Toolbox PPC Final²,
        from:obj {
            form:indx,
            want:type(PRJD),
            seld:1,
            from:'null'()
        }
    }, 
    obj {
        form:name, 
        want:type(TRGT),
        seld:³MacOS Toolbox Carbon Final²,
        from:obj {
            form:indx,
            want:type(PRJD),
            seld:1,
            from:'null'()
        }
    }
]


> 
>> The element then returns nothing to the prop(name) call.
> 
> Well, there is something wrong with your code there.
> 
> @targslist = $CW->obj(targets => gAll, of=> $doc);
> 
> What you really would want is:
> 
> @targslist = $CW->obj(targets => gAll, $doc);

> @targslist = $CW->obj(targets => $doc);

Indeed this does partially fix the problem. Now the get($CW->prop(name =>
$targ) call works for the element in the list, but the list is still only
one element long.

Semi-fixed code looks like:

$doc = $CW->get($CW->obj(document => whose(name=> equals => "foo.mcp")));
@targslist = $CW->obj(targets => gAll, $doc);

print "Targslist contains " . scalar(@targslist) . "items.\n";
foreach $targ (@targslist) {
    $name = $CW->get($CW->prop(name => $targ));
    print $name;
    }

> But in your example, $doc is not a property, it is an object.  The "of" is
> superfluous.  Here, the vocabulary of AppleScript gets in the way: in cases
> OTHER than for a property, an "of" in AppleScript is usually translated as
> "," (or "=>").

I have a sneaking suspicion that many of my problems are the result of
trying to mix Applescript thinking with Perl thinking. While I've got a fair
amount of Perl code under my belt now this is my first attempt to replace
AppleScript with Perl.

One question I do have though, is why the previous bad call didn't generate
an error in $^E?


>> Any suggestions appreciated. Examples that show how to parse CodeWarrior
>> errors from Perl (my next project) would be even better.
> 
> What errors would those be?  Can you give an example?

Certainly... I should mention I haven't seriously worked on this part yet,
but I was hoping maybe a corrected example of the above stuff would help me
understand the difference between constructing objects to pass to the get
call and prop calls to read properties. Your discussion of "of" plus some
more experimentation has helped me grasp that under the hood Applescript is
making the difference between the two more-or-less transparent (which is
apparently not the case with Perl).

The CodeWarrior IDE has a call (cut from the Glue pod):

    $obj->make_project([externaleditor => bool])
        Make the current project (MMPR/Make)
        Reply type: ErrM
        Parameters:
            direct object (----):
            externaleditor (Errs): Should the contents of the message window
                  be returned to the caller?

I called this as:
my @errors = $CW->make_project(externaleditor => 1);

Initially I thought that the reply would be a record which Glue would
magically transform to a hash I could parse handily. Now I'm beginning to
understand that what I'm actually going to get is a list of object
references like (again cut from the glue pod):

    error_information (ErrM)
        Describes a single error or warning from the compiler or the linker.
        Properties:
           disk_file (file/fss ): The file where the error occurred.  May
            not be returned for certain kinds of errors (eg, link errors).
            linenumber (ErrL/long): The line in the file where the error
             occurred.  May not be returned for certain kinds of errors (eg,
             link errors).
            message (ErrS/TEXT): The error or warning message.
            messagekind (ErrT/ErrT): The type of error or warning.

Where ErrT is an enum:
    'ErrT'     
       compiler_warning (ErCW)
        definition (ErDf)
        linker_warning (ErLW)
        compiler_error (ErCE)
        generic_error (ErGn)
        linker_error (ErLE)
        information (ErIn)
        find_result (ErFn)

I assume I can reach into these by iterating the list of error_information
objects and using prop() calls to read the fields I need. The parts that
confuse me are:

 - Do I need to call $CW->get() around those prop calls? Since the error
record returns all the data in the Errs object why can't I read the contents
directly? Do I really need to call get() again? Does the get() call even
generate an event in this case?

- How do I comparision test the enum messagekind field? I'm only interested
in some of the ErrT types. I think I could do a whose() to split the list
various ways, but that seems again like more events than should be needed.

Again, perhaps here again AppleScript has made me lazy. A script like:

Make Project with ExternalEditor

Returns:
{
    {
        class:Error Information,
        messageKind:compiler error,
        message:"declaration syntax error ",
        file:file "Denmark:Desktop Folder:foo:SimpleAlert.c",
        lineNumber:23
    }, 
    {
        class:Error Information,
        messageKind:compiler warning,
        message:"function has no prototype ",
        file:file "Denmark:Desktop Folder:foo:SimpleAlert.c",
        lineNumber:24
    }
}

Which I can loop over pretty easily in Applescript. Now I understand that
although I thought this was a record, what I've really got is a object where
calls like (lineNumber of error) are being automagically turned into
property reads.

Thanks again for you help... And for Mac::Glue. I shudder to think if I was
trying to do this stuff using the old AppleEvent modules.

Alex
 


# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org