Thread overview | ||||||
---|---|---|---|---|---|---|
|
July 28, 2019 Calling / running / executing .d script from another .d script | ||||
---|---|---|---|---|
| ||||
Right now, I'm thinking what is correct way to run another .d script from a .d script. Do you have any suggestions? |
July 28, 2019 Re: Calling / running / executing .d script from another .d script | ||||
---|---|---|---|---|
| ||||
Posted in reply to BoQsc | 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
|
July 28, 2019 Re: Calling / running / executing .d script from another .d script | ||||
---|---|---|---|---|
| ||||
Posted in reply to BoQsc | 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
|
July 29, 2019 Re: Calling / running / executing .d script from another .d script | ||||
---|---|---|---|---|
| ||||
Posted in reply to BoQsc | 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"]); ?
|
Copyright © 1999-2021 by the D Language Foundation