On 18/01/2013 08:09, Rob T wrote:
On Friday, 18 January 2013 at 07:34:35 UTC, Jacob Carlborg wrote:

You cannot both have CTFE/inlining/templates and hide the source code.
It's the same as in C++.

Yes I am aware of that limitation, nothing can be done except lose the
flexibility of templates and so forth, or keep it and expose the source
code.

For classes and structs, I have no idea how to leave out the
implementation details.

You can either use an interface or just not provide an implementation
for the methods. Note that it's perfectly fine to have a method in D
without an implementation even it's not abstract. This is to support
the use case you have here and separate compilation.

I figure that's the best approach, but I am not sure how to not supply
the implementation for a module, since in D there doesn't seem to be a
separation of interface and implementation.

I guess you would need to list the fields on classes/structs, again
that's just like C++.

I have not yet seen examples or documentation explaining how to separate
interface and implementation from a class or struct. Are you sure this
can be done?

--rt

Yes you can. I do it with a library of mine; most of it is compiled into a static lib, due to the fact that it's large enough it even slows down dmd to the point of being irritating.

I maintain the .di file(s) semi separately by hand at the moment.

So take your library, compile it to a static lib with:

dmd -lib -ofmyStatic.lib 1.d 2.d 3.d

The static lib will (obviously) contain object code for anything which is immediately compilable.

Then generate you .di files (you might need to xp with this, it's been ages since I worked it out)

dmd -c -o- -HdlibImportsDir 1.d

Then edit your .di in libImportsDir\1.di and delete any of the implementation that you don't want exposed.

Client apps use the .di files and link to the static lib.
If you leave an implementation in the .di I think that takes precedence over the static lib; but I've not tested that.

Generating the .di files for a large project is a pain in the ass though, so I've got a fairly sophisticated bunch of powershell scripts to handle it all and at some point I'll write my own .di generator that will use specially formatted comments to control what stays & what gets chucked, if that doesn't get added to dmd before I get off my back side.

--
My enormous talent is exceeded only by my outrageous laziness.
http://www.ssTk.co.uk

Reply via email to