Fully dynamic d by opDotExp overloading
Leandro Lucarella
llucax at gmail.com
Fri Apr 17 06:44:09 PDT 2009
davidl, el 17 de abril a las 14:31 me escribiste:
> After tweaking dmd a bit litte, i get the dotexp overloading work.
>
> The following is the test code:
> import std.stdio;
> class c
> {
>
> B opDotExp(char[] methodname,...)
> {
> writefln("god it works ", methodname);
> return new B();
> }
> void opAdd(int j)
> {
>
> }
> void test()
> {
> }
> }
>
> class a:c
> {
>
> }
>
> class B
> {
> int i;
> B opAssign(int k){
> i=k;
> return this;
> }
> }
>
> char[] v1;
>
> void func(char[] v, ...){}
>
> void main()
> {
> a v=new a;
> v.test();
> v.dynamicmethod(3,4);
> //v.qq = 5;
> writefln((v.qq = 5).i);
> }
>
> it generates the output:
> god it works dynamicmethod
> god it works qq
> 5
>
> Any comments? Do you like this feature?
This is awsome indeed. I'd love to see it in the specs. The suggestion of
making opDotExp a template it's good one too. I guess that now that opDot
is replaced by alias this, opDot can be used for this instead of opDotExp.
I don't fully understand the example though. In writefln((v.qq = 5).i),
how is that B.i is assigned to 5 if the opDotExp("qq", 5) don't propagate
the 5 to the new B()?
Thanks for the great job.
--
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
Que barbaridad, este país se va cada ves más pa' tras, más pa' tras...
-- Sidharta Kiwi
More information about the Digitalmars-d
mailing list