digitalmars.D.learn - Calling / running / executing .d script from another .d script
- BoQsc (2/2) Jul 28 2019 Right now, I'm thinking what is correct way to run another .d
- Max Haughton (6/8) Jul 28 2019 You'd need to bring a compiler with you and then build it into a
- =?UTF-8?Q?Ali_=c3=87ehreli?= (26/28) Jul 28 2019 I can be easier than a shared library solution that Max Haughton
- Kagamin (2/4) Jul 29 2019 You mean something like execute(["rdmd", "another.d"]); ?
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
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
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
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