How to pack types with variables in one message to send it to another thread? [tuple]

MarisaLovesUsAll via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Sep 7 05:39:51 PDT 2014


Thanks for reply.
> Strings are immutable so thats ok. A class instance that isn't 
> immutable isn't.

It's not a class instance, it's a class type. Something like 
`cast(Sprite) null` in parameters. It can be replaced by string 
"Sprite", but in this case I can't use receive() as it is. E.g.

send(tid,gameobjectId,"Sprite","reload");
//must call sprite.reload();

send(tid,gameobjectId,"Animation","reload");
//must call animation.reload();

>Just have separate receiving functions per the data type.
But both messages are (int, string, string) so they can't be 
separate by different receiving functions. It will be better if 
messages was (int, Sprite, string) / (int, Animation, string). 
And it solves my problem. :) But I don't know how to achieve this.


> In other words Variant is overkill.
> It basically just wraps a piece of data so that it can be 
> passed around without knowing its type. Which in this case is 
> bad.
> You would end up having to know the datatype to do anything 
> with it anyway.
Then I need something like Variant[] to store this data in array.

MyVariant[] args;
if(args[0] == typeid(int))
{
     if(args[1] == "Sprite") {}
     if(args[1] == "Animation") {}
}
etc.

I'm trying to make something like messages in Smalltalk (?), but 
between threads. Thread can receive anything and thread decides 
what to do on its own.


More information about the Digitalmars-d-learn mailing list