www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Compiling D inside of a D program

reply "Mineko" <uminekorox gmail.com> writes:
This is a fairly basic question but I can't find any good 
answers, so I'm asking..

Anyways, I want to be able to invoke the D compiler, whichever 
that might be from inside of a D program, so I can say, compile a 
D script on-the-fly in some game, it's just an idea though.

To be even more to the point, how can I invoke the D compiler 
inside of a D program, also, do I need to bundle said D compiler 
with my program or does D have some compilation feature inside of 
an already compiled program (Which I doubt)?
Dec 21 2013
next sibling parent "thedeemon" <dlang thedeemon.com> writes:
On Saturday, 21 December 2013 at 08:55:04 UTC, Mineko wrote:
 To be even more to the point, how can I invoke the D compiler 
 inside of a D program, also, do I need to bundle said D 
 compiler with my program or does D have some compilation 
 feature inside of an already compiled program (Which I doubt)?
D runtime doesn't include any compilation abilities, it's not a Lisp. You'll need to invoke the compiler as a separate process. Look at this example: http://dlang.org/phobos/std_process.html#.execute
Dec 21 2013
prev sibling next sibling parent "Andrea Fontana" <nospam example.com> writes:
I still hope they make DMD available as shared/static library 
just like tinyc compiler!


On Saturday, 21 December 2013 at 08:55:04 UTC, Mineko wrote:
 This is a fairly basic question but I can't find any good 
 answers, so I'm asking..

 Anyways, I want to be able to invoke the D compiler, whichever 
 that might be from inside of a D program, so I can say, compile 
 a D script on-the-fly in some game, it's just an idea though.

 To be even more to the point, how can I invoke the D compiler 
 inside of a D program, also, do I need to bundle said D 
 compiler with my program or does D have some compilation 
 feature inside of an already compiled program (Which I doubt)?
Dec 21 2013
prev sibling parent reply "Kelet" <kelethunter gmail.com> writes:
On Saturday, 21 December 2013 at 08:55:04 UTC, Mineko wrote:
 This is a fairly basic question but I can't find any good 
 answers, so I'm asking..

 Anyways, I want to be able to invoke the D compiler, whichever 
 that might be from inside of a D program, so I can say, compile 
 a D script on-the-fly in some game, it's just an idea though.

 To be even more to the point, how can I invoke the D compiler 
 inside of a D program, also, do I need to bundle said D 
 compiler with my program or does D have some compilation 
 feature inside of an already compiled program (Which I doubt)?
Hi, I was also interested in this topic. My research suggests that there is no easy or safe way to do this at the moment, as thedeemon suggests. Although I think it's worth offering a possible alternative: using a scripting language binding like LuaD[1], DerelictLua[2], or pyd[3]. From here, you can expose some functions/variables between them, and solve a lot of the same problems. That being said, I think it would be useful to have something like JavaCompiler[4]. It's not an optimal solution, but combined with a minimal compiler package it could help a lot. As far as I know, you need to ask permission to distribute DMD with your application, so it may be safer to include GDC or LDC if you want to go this route. Or ask Walter, of course. [1]: https://github.com/JakobOvrum/LuaD [2]: https://github.com/DerelictOrg/DerelictLua [3]: https://bitbucket.org/ariovistus/pyd [4]: http://docs.oracle.com/javase/7/docs/api/javax/tools/JavaCompiler.html Regards, Kelet
Dec 21 2013
parent reply "Mineko" <uminekorox gmail.com> writes:
On Saturday, 21 December 2013 at 10:00:10 UTC, Kelet wrote:
 On Saturday, 21 December 2013 at 08:55:04 UTC, Mineko wrote:
 This is a fairly basic question but I can't find any good 
 answers, so I'm asking..

 Anyways, I want to be able to invoke the D compiler, whichever 
 that might be from inside of a D program, so I can say, 
 compile a D script on-the-fly in some game, it's just an idea 
 though.

 To be even more to the point, how can I invoke the D compiler 
 inside of a D program, also, do I need to bundle said D 
 compiler with my program or does D have some compilation 
 feature inside of an already compiled program (Which I doubt)?
Hi, I was also interested in this topic. My research suggests that there is no easy or safe way to do this at the moment, as thedeemon suggests. Although I think it's worth offering a possible alternative: using a scripting language binding like LuaD[1], DerelictLua[2], or pyd[3]. From here, you can expose some functions/variables between them, and solve a lot of the same problems. That being said, I think it would be useful to have something like JavaCompiler[4]. It's not an optimal solution, but combined with a minimal compiler package it could help a lot. As far as I know, you need to ask permission to distribute DMD with your application, so it may be safer to include GDC or LDC if you want to go this route. Or ask Walter, of course. [1]: https://github.com/JakobOvrum/LuaD [2]: https://github.com/DerelictOrg/DerelictLua [3]: https://bitbucket.org/ariovistus/pyd [4]: http://docs.oracle.com/javase/7/docs/api/javax/tools/JavaCompiler.html Regards, Kelet
Would it be legal to have my program automatically download some dmd binary, that way I could always keep it up to date? Given Walter here doesn't absolutely forbid my program does that.
Dec 21 2013
parent reply "John Colvin" <john.loughran.colvin gmail.com> writes:
On Saturday, 21 December 2013 at 21:58:16 UTC, Mineko wrote:
 On Saturday, 21 December 2013 at 10:00:10 UTC, Kelet wrote:
 On Saturday, 21 December 2013 at 08:55:04 UTC, Mineko wrote:
 This is a fairly basic question but I can't find any good 
 answers, so I'm asking..

 Anyways, I want to be able to invoke the D compiler, 
 whichever that might be from inside of a D program, so I can 
 say, compile a D script on-the-fly in some game, it's just an 
 idea though.

 To be even more to the point, how can I invoke the D compiler 
 inside of a D program, also, do I need to bundle said D 
 compiler with my program or does D have some compilation 
 feature inside of an already compiled program (Which I doubt)?
Hi, I was also interested in this topic. My research suggests that there is no easy or safe way to do this at the moment, as thedeemon suggests. Although I think it's worth offering a possible alternative: using a scripting language binding like LuaD[1], DerelictLua[2], or pyd[3]. From here, you can expose some functions/variables between them, and solve a lot of the same problems. That being said, I think it would be useful to have something like JavaCompiler[4]. It's not an optimal solution, but combined with a minimal compiler package it could help a lot. As far as I know, you need to ask permission to distribute DMD with your application, so it may be safer to include GDC or LDC if you want to go this route. Or ask Walter, of course. [1]: https://github.com/JakobOvrum/LuaD [2]: https://github.com/DerelictOrg/DerelictLua [3]: https://bitbucket.org/ariovistus/pyd [4]: http://docs.oracle.com/javase/7/docs/api/javax/tools/JavaCompiler.html Regards, Kelet
Would it be legal to have my program automatically download some dmd binary, that way I could always keep it up to date? Given Walter here doesn't absolutely forbid my program does that.
To the best of my knowledge it's totally ok to have your program download the latest zip from dlang.org on the client machine and use that.
Dec 21 2013
parent reply "Mineko" <uminekorox gmail.com> writes:
On Saturday, 21 December 2013 at 22:07:42 UTC, John Colvin wrote:
 To the best of my knowledge it's totally ok to have your 
 program download the latest zip from dlang.org on the client 
 machine and use that.
Sounds good to me, I more or less know what to do now, I'll be using DMD because of it's fast code compilation which is going to be KEY especially to multiplayer games, I would have LIKED to use GDC, but like I said, fast compilation times. (Or perhaps someone has an idea there..?)
Dec 21 2013
parent reply "John Colvin" <john.loughran.colvin gmail.com> writes:
On Saturday, 21 December 2013 at 22:18:58 UTC, Mineko wrote:
 On Saturday, 21 December 2013 at 22:07:42 UTC, John Colvin 
 wrote:
 To the best of my knowledge it's totally ok to have your 
 program download the latest zip from dlang.org on the client 
 machine and use that.
Sounds good to me, I more or less know what to do now, I'll be using DMD because of it's fast code compilation which is going to be KEY especially to multiplayer games, I would have LIKED to use GDC, but like I said, fast compilation times. (Or perhaps someone has an idea there..?)
How fast do you actually need it to be?
Dec 21 2013
parent reply "Mineko" <uminekorox gmail.com> writes:
On Saturday, 21 December 2013 at 22:51:53 UTC, John Colvin wrote:
 On Saturday, 21 December 2013 at 22:18:58 UTC, Mineko wrote:
 On Saturday, 21 December 2013 at 22:07:42 UTC, John Colvin 
 wrote:
 To the best of my knowledge it's totally ok to have your 
 program download the latest zip from dlang.org on the client 
 machine and use that.
Sounds good to me, I more or less know what to do now, I'll be using DMD because of it's fast code compilation which is going to be KEY especially to multiplayer games, I would have LIKED to use GDC, but like I said, fast compilation times. (Or perhaps someone has an idea there..?)
How fast do you actually need it to be?
Fast enough to where the engine is not spending 5 minutes compiling a heavily scripted (multiplayer usually) game, perhaps gdc -0fast would do it?
Dec 21 2013
parent "John Colvin" <john.loughran.colvin gmail.com> writes:
On Saturday, 21 December 2013 at 23:00:20 UTC, Mineko wrote:
 On Saturday, 21 December 2013 at 22:51:53 UTC, John Colvin 
 wrote:
 On Saturday, 21 December 2013 at 22:18:58 UTC, Mineko wrote:
 On Saturday, 21 December 2013 at 22:07:42 UTC, John Colvin 
 wrote:
 To the best of my knowledge it's totally ok to have your 
 program download the latest zip from dlang.org on the client 
 machine and use that.
Sounds good to me, I more or less know what to do now, I'll be using DMD because of it's fast code compilation which is going to be KEY especially to multiplayer games, I would have LIKED to use GDC, but like I said, fast compilation times. (Or perhaps someone has an idea there..?)
How fast do you actually need it to be?
Fast enough to where the engine is not spending 5 minutes compiling a heavily scripted (multiplayer usually) game, perhaps gdc -0fast would do it?
-Ofast means fast code, not fast compilation. For a scripting layer, dmd is probably the best choice. If the scripts get really big you might still run in to some problems. If they remain small (or at least the bit that neds recompiling is small) then gdc/ldc would still be viable.
Dec 21 2013