www.digitalmars.com         C & C++   DMDScript  

D - D & Phobos

reply Razvan <Razvan_member pathlink.com> writes:
Hi folks,

I saw the D language and it is just great. I'm planning to use it at some big
projects and I started to port a very good GUI library (www.fox-toolkit.org) to
D. This is done in a big percentage and now I'm working to make a simple fox
dialog editor in D. I'm thinking later to make these freely available.
When working with D, i saw some things for which I need some explanations:

1. Is it possible for a delegate to an object method do get the object from it?
Like: void *getDelegateObject(void *delegate). For now I need to pass to some
functions both the delegate variable to an object method and the object itself.

2. About the ~ operator, now to add a new element to an array I'm using:
array.length=array.length+1; array[array.length-1]=obj; 
Can be a simpler method to do this? Because to add objects to arrays is a very
common task (I know about the performance penalities of this method, but I'm
talking about 3-4 addings, for which i don't want to complicate myself with
other things).

3. For arrays, how the "sort" func works? It uses the cmp method, so i can
implement cmd on my objects and they will get sorted in an array?

4. the void* type is different from other pointers? For example when I'm trying
to do something like:
char []s="Zero terminated string\0";
void *pv=cast(void*)s;    //it works
char *pc=cast(char*)s;    //it didnt work

Thank you,
Razvan
May 24 2004
parent reply Andy Friesen <andy ikagames.com> writes:
Razvan wrote:

 Hi folks,
Hi! Could you do us a favour and post to digitalmars.D instead of here? This newsgroup is deprecated.
 I saw the D language and it is just great. I'm planning to use it at some big
 projects and I started to port a very good GUI library (www.fox-toolkit.org) to
 D. This is done in a big percentage
Nice!
 and now I'm working to make a simple fox
 dialog editor in D. I'm thinking later to make these freely available.
 When working with D, i saw some things for which I need some explanations:
 
 1. Is it possible for a delegate to an object method do get the object from it?
 Like: void *getDelegateObject(void *delegate). For now I need to pass to some
 functions both the delegate variable to an object method and the object itself.
Only if you're willing to cheat: union EvilDelegateCheat { delegate void(...) dlg; struct { void* object; // maybe I got these backwards void* function; } } I would avoid this if at all possible, though, for obvious reasons.
 2. About the ~ operator, now to add a new element to an array I'm using:
 array.length=array.length+1; array[array.length-1]=obj; 
array ~= obj; // exactly what you want
 3. For arrays, how the "sort" func works? It uses the cmp method, so i can
 implement cmd on my objects and they will get sorted in an array?
opCmp, actually, and I think so.
 4. the void* type is different from other pointers? For example when I'm trying
 to do something like:
 char []s="Zero terminated string\0";
 void *pv=cast(void*)s;    //it works
 char *pc=cast(char*)s;    //it didnt work
That's odd. This will work: char* pc = &s[0]; -- andy
May 24 2004
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Andy Friesen wrote:

<snip>
 Only if you're willing to cheat:
 
 union EvilDelegateCheat {
    delegate void(...)  dlg;
    struct {
       void* object; // maybe I got these backwards
       void* function;
    }
 }
<snip> Wouldn't this be implementation dependent? Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
May 25 2004
parent Andy Friesen <andy ikagames.com> writes:
Stewart Gordon wrote:
 Andy Friesen wrote:
 
 <snip>
 
 Only if you're willing to cheat:

 union EvilDelegateCheat {
    delegate void(...)  dlg;
    struct {
       void* object; // maybe I got these backwards
       void* function;
    }
 }
<snip> Wouldn't this be implementation dependent?
Hence the 'evil' qualifier. :) -- andy
May 25 2004