www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - how to hide sources?

reply Wakie <Wakie_member pathlink.com> writes:
Hello! Help me, pls. I don't understand how I can distribute my libs w/o
sources?
When I produce .OBJ files and try to link them to main program DMD wants access
to original *.D files!
Sep 15 2005
next sibling parent reply Derek Parnell <derek psych.ward> writes:
On Thu, 15 Sep 2005 10:05:09 +0000 (UTC), Wakie wrote:

 Hello! Help me, pls. I don't understand how I can distribute my libs w/o
 sources?
 When I produce .OBJ files and try to link them to main program DMD wants access
 to original *.D files!

For each module in the library you need to create a 'header' module. This is identical to the original module source code, except that it only contains public IDENTIFIERS and no executable code. You then distribute your library and the header modules. For example, if you have a module file called foo_m.d, like this ... <code> module foo_m; private { import std.string; int myValue; } class Foo { private { int _x; long _y; } this() { _x = 1; _y = 1; } char[] toString() { return std.string.format("[%d:%d]", _x, _y); } int x() {return _x + myValue;} long y() {return _y + myValue;} } </code> You would create a header file, ALSO called foo_m.d but obviously in a different folder, like this ... <code> module foo_m; class Foo { this(); char[] toString(); int x(); long y(); } </code> You would create the library and distribute the library file AND the cut-down 'header' source file. -- Derek Parnell Melbourne, Australia 15/09/2005 8:09:48 PM
Sep 15 2005
parent reply Newbie <Newbie_member pathlink.com> writes:
For each module in the library you need to create a 'header' module.

OK, Derek, thank you very much for excellent answer! I tried, it works. :) What you think about to add some tool which will do this automatically? (like h->.d) And second question: I found a lot of docs for D, but still not sure I have FULL description of the language. For example I frequently see things like "private import". I know directive "import" but never met explanation for "private import". Where I can found full spec for D?
Sep 15 2005
parent reply J Thomas <jtd514 ameritech.net> writes:
private means private same as it does as a class attribute

you can:

private
{
   import something;
}

or

private import something;

it means import it into the current module only, then other modules that 
import this module wont also import somethig


Newbie wrote:
For each module in the library you need to create a 'header' module.

OK, Derek, thank you very much for excellent answer! I tried, it works. :) What you think about to add some tool which will do this automatically? (like h->.d) And second question: I found a lot of docs for D, but still not sure I have FULL description of the language. For example I frequently see things like "private import". I know directive "import" but never met explanation for "private import". Where I can found full spec for D?

Sep 15 2005
parent Newbie <Newbie_member pathlink.com> writes:
it means import it into the current module only, then other modules that 
import this module wont also import somethig

Strange behaviour, but it goes as you say. :) Thanks.
Sep 15 2005
prev sibling parent Burton Radons <burton-radons smocky.com> writes:
Wakie wrote:
 Hello! Help me, pls. I don't understand how I can distribute my libs w/o
 sources?
 When I produce .OBJ files and try to link them to main program DMD wants access
 to original *.D files!

Try digc: http://www.smocky.com/index.php/Digc It helps with creating library files and it appends a stripped source to the end of the library so that you only need to distribute one file. During compilation of other programs, if it detects that the library is used (through an import) it recreates the headers and links in what's needed.
Sep 16 2005