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
>
_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk