www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - opDispatch not working

reply Mike Brown <mikey.be gmail.com> writes:
Hi All,

Im still experimenting with WASM and D - I really would like to 
be able to use reference types. I think I can get there with the 
metaprogramming abilities in D.

I'm trying to get the foundations right, I need a reference-like 
handle - which I've named "ptr". I'm trying to see how I can 
dispatch method calls to the underline object, I've tried 
opDispatch.

https://godbolt.org/z/a1Tc4ErTv

But I can't get it to fire? What am I missing?

P.S. Is it also possible to provide a way to implicitly cast from 
ptr!byte to ptr!\<a type> ?

Kind regards,
Mike Brown
Jun 05
parent reply drug <drug2004 bk.ru> writes:
05.06.2021 18:15, Mike Brown пишет:
 Hi All,
 
 Im still experimenting with WASM and D - I really would like to be able 
 to use reference types. I think I can get there with the metaprogramming 
 abilities in D.
 
 I'm trying to get the foundations right, I need a reference-like handle 
 - which I've named "ptr". I'm trying to see how I can dispatch method 
 calls to the underline object, I've tried opDispatch.
 
 https://godbolt.org/z/a1Tc4ErTv
 
 But I can't get it to fire? What am I missing?
 
 P.S. Is it also possible to provide a way to implicitly cast from 
 ptr!byte to ptr!\<a type> ?
 
 Kind regards,
 Mike Brown
incomplete `cast` I would say. You did: ```D mixin("cast(T*)obj."~name)(vals); ``` instead of ```D mixin("(cast(T*)obj)."~name)(vals); ``` i.e. you try to call method `test` using a pointer to void and then try to cast it to a pointer to T.
Jun 05
parent Mike Brown <mikey.be gmail.com> writes:
On Saturday, 5 June 2021 at 15:23:09 UTC, drug wrote:
 05.06.2021 18:15, Mike Brown пишет:
 [...]
incomplete `cast` I would say. You did: ```D mixin("cast(T*)obj."~name)(vals); ``` instead of ```D mixin("(cast(T*)obj)."~name)(vals); ``` i.e. you try to call method `test` using a pointer to void and then try to cast it to a pointer to T.
Thank you!!
Jun 05