Data slots in parents not cloning?

Mildred Ki'Lya ml.mildred593 at gmail.com
Tue Aug 25 16:58:34 UTC 2009


On 08/25/2009 06:40 PM, Jeremy Cowgar wrote:
> Here are just the important snippets of code. The problem is that all my
> buttons contain the same "handle"...
>
> //===========================================
> // control.li
> Section Header
>   + name := CONTROL;
>
> Section Private
>   + handle:POINTER;
>
>   - set_handle h:POINTER <- 
>   (
>     handle := h;
>   );
>
> //===========================================
> // button.li
> Section Header
>   + name := BUTTON;
>
> Section Inherit
>   + parent:CONTROL := CONTROL;
>
> Section Public
>   - make title:ABSTRACT_STRING <-
>   ( + result:BUTTON;
>     + h:POINTER;
>     + n_title:NATIVE_ARRAY(CHARACTER);
>
>     n_title := title.to_external;
>     h := `IupButton(@n_title)`:POINTER;
>
>     result := BUTTON.clone;
>     result.set_handle h;
>     result
>   );
>
> //===========================================
> // example.li
> Section Header
>   + name := EXAMPLE;
>
> Section Public
>   - main <- 
>   ( + b1, b2:BUTTON;
>     b1 := BUTTON.make "Hello";
>     b1.handle.println;
>     b2 := BUTTON.make "Goodbye";
>     b2.handle.println;
>
>     "Buttons after all have been created:".println;
>     b1.handle.println;
>     b2.handle.println;
>   );
>   
> //===========================================
>
> The output is something like:
>
> 13990D8
> 14209A3
> Buttons after all have been created:
> 14209A3
> 14209A3
>
> Any thoughts on this?
>
>   


I don't quite understand the make slot. Is there a result, or is there
not? The compiler should raise an error when you affect b1 to
BUTTON.make as it doesn't return anything.

The, I think you might have a problem with the inheritance. When you
clone BUTTON, both the original and the copy have the same parent, and
the same handle. Cloning only clone the current object, and do not clone
referenced objects (in this case the parent).

I think you might want to write:

Section Header
  + name := BUTTON;

Section Inherit
  + parent:Expanded CONTROL;


This way, when you clone the BUTTON, the values in CONTROL are copied as
well, since it is Expanded.

The difference between an Expanded object and a non Expanded object is
like the difference between a structure in C and a pointer to a
structure in C.


Mildred

-- 
Mildred Ki'Lya
╭───────── mildred593@online.fr ──────────
│ Jabber, GoogleTalk: <mildred at jabber.fr>
│ Website: <http://ki.lya.online.fr>           GPG ID: 9A7D 2E2B
│ Fingerprint: 197C A7E6 645B 4299 6D37 684B 6F9D A8D6 9A7D 2E2B


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: OpenPGP digital signature
URL: <http://lists.alioth.debian.org/pipermail/lisaac-devel/attachments/20090825/73f2f01b/attachment.pgp>


More information about the Lisaac-devel mailing list