www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Calling / running / executing .d script from another .d script

reply BoQsc <vaidas.boqsc gmail.com> writes:
Right now, I'm thinking what is correct way to run another .d 
script from a .d script. Do you have any suggestions?
Jul 28 2019
next sibling parent Max Haughton <maxhaton gmail.com> writes:
On Sunday, 28 July 2019 at 12:56:12 UTC, BoQsc wrote:
 Right now, I'm thinking what is correct way to run another .d 
 script from a .d script. Do you have any suggestions?
You'd need to bring a compiler with you and then build it into a shared library (then dlopen it). To do this you'd need a clear API defined in the file to be compiled, so you can call it. If you want to use druntime in said file you need to use loadLibrary in core instead of dlopen
Jul 28 2019
prev sibling next sibling parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 07/28/2019 05:56 AM, BoQsc wrote:
 Right now, I'm thinking what is correct way to run another .d script 
 from a .d script. Do you have any suggestions?
I can be easier than a shared library solution that Max Haughton described. (None of the following code are compiled.) If you have the following code in foo.d: module foo; int foo(int i) { return i + 42; } You can call it from bar.d like this: module bar; import foo; int bar(int i) { return foo(i); } Then you can combine the two modules with the following main: module main; import bar; void main() { bar(7); } Here is how to compile the whole program: dmd main.d bar.d foo.d -of=my_program However, it can be even simpler with dmd's -i command line switch, which automatically includes all imported modules in the program: dmd main.d -of=my_program Ali
Jul 28 2019
prev sibling parent Kagamin <spam here.lot> writes:
On Sunday, 28 July 2019 at 12:56:12 UTC, BoQsc wrote:
 Right now, I'm thinking what is correct way to run another .d 
 script from a .d script. Do you have any suggestions?
You mean something like execute(["rdmd", "another.d"]); ?
Jul 29 2019