GUI program on Mac OS in D?

Jacob Carlborg doob at me.com
Wed Dec 13 15:07:46 UTC 2017


On 2017-12-13 13:18, mrphobby wrote:

> I have been taking a look at your example. Looks pretty neat! Some 
> advanced mixin stuff there that looks pretty useful.

They're pretty basic ;)

> However, as far as 
> I can tell there is no handling of retain/release.

No, that's correct.

> How would you 
> incorporate this into your mixin system without having to put "release" 
> in all the interface definitions?

You can add methods for retain/release in the ClassTrait template [1].

> Would it be possible to somehow hook 
> this up automatically to the D destructor perhaps? Interested in hearing 
> your thoughts on this!

As far as I know, the destructor is only called (automatically by the 
GC). Since the Objective-C objects are not created using the GC the 
destructor will never be called. I don't think it's possible to 
implement reference counting (that would call retain/release) for 
classes in D, since it's not possible to overload the assignment 
operator for classes [2] or implement a postblit [3]. The only option, 
as far as I know, would be to wrap the class in a struct that calls 
retain/release automatically. But then you need to box/unbox the wrapped 
class constantly and all the method signatures would probably need to 
use this wrapper as well.

[1] 
https://github.com/jacob-carlborg/d_webkit_test/blob/master/source/foundation/util.d#L28

[2] https://dlang.org/spec/operatoroverloading.html#assignment
[3] https://dlang.org/spec/struct.html#struct-postblit

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list