help-smalltalk
[Top][All Lists]
Advanced

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

Re: [Help-smalltalk] Question on CStruct


From: Paolo Bonzini
Subject: Re: [Help-smalltalk] Question on CStruct
Date: Sat, 29 Dec 2012 15:27:17 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0

Il 09/12/2012 22:57, Thomas Girard ha scritto:
> Hello,
> 
> Can we use instance variables in CStruct?

Yes.

> But embedding this CStruct with instance variable into another CStruct
> does *not* work:
>> CStruct subclass: EmbeddedSequence [
>>     <declaration: #( (#days #uShort)
>>                      (#intervals #{Sequence}) )>
>> ]
>>
>> Eval [
>>     |eq|
>>     eq := EmbeddedSequence new.
>>     eq intervals arrayType: CBoolean.
>>     eq intervals arrayType inspect.
>> ]
> because we get an UndefinedObject for arrayType. Somehow it seems the
> instance variable arrayType cannot be reached.

It does work.  The problem is that each invocation of #intervals creates
a new instance of Sequence.  This is the definition of the method:

    intervals [
       ^self at: 8 type: (CType cObjectType: Sequence)
    ]

Try this snippet:

    Eval [
        |eq int|
        eq := EmbeddedSequence new.
        int := eq intervals.
        int arrayType: CBoolean.
        int arrayType printNl.
        eq intervals arrayType printNl.
        (int = eq intervals) printNl.
        (int == eq intervals) printNl
    ]

You'll get:

    CBoolean
    nil
    true
    false

Paolo

> I would expect either gst to reject the former snippet if instance
> variable in CStruct is not allowed, or to correctly return what was
> sent in the second snippet. Am I missing something?
> 
> Thanks,
> Regards,
> 
> Thomas
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]