Re: Is it possible to execute a function inside .d script that has no main function?

2019-07-12 Thread BoQsc via Digitalmars-d-learn

On Thursday, 11 July 2019 at 10:41:38 UTC, Alex wrote:

On Thursday, 11 July 2019 at 09:43:55 UTC, BoQsc wrote:

Here I have a file named: module.d


[...]


There is no main() function since, I want to import this 
module, into another .d file.


( If I try to import and module.d does have main() function I 
get this error: )

[...]






I would like to launch function "interestingFunction()" 
directly using rdmd.

Is it possible to achieve that by any way?





I tried to launch the whole file, but it gave me some weird 
output:

[...]


If you are trying to test a function separately from other 
functions, e.g. for testing, then you are approaching unit 
testing.
You could write a unit test block just under the function to 
test like

unittest
{
  interestingFunction;
}

and launch it via rdmd... don't know the syntax right now. But 
here is something:

https://stackoverflow.com/questions/10694994/rdmd-is-not-running-unit-tests

So, I assume something like
rdmd -unittest --main module.d


Hmm, maybe I'll just rename module.d to module_library.d and 
place it in a folder,
then create a new module_run.d file that would launch the 
functions of module_library.d



module\module_library.d
module\module_run.d
README.md


Maybe even place a README.md file explaining how I come up with 
this idea.


And when in need of executing it, I'll just type:

rdmd module\module_run.d


Re: Is it possible to execute a function inside .d script that has no main function?

2019-07-11 Thread Alex via Digitalmars-d-learn

On Thursday, 11 July 2019 at 09:43:55 UTC, BoQsc wrote:

Here I have a file named: module.d


import std.stdio   : writeln;

void interestingFunction(){
writeln("Testing");
}


There is no main() function since, I want to import this 
module, into another .d file.


( If I try to import and module.d does have main() function I 
get this error: )
otherFile.d(13): Error: only one main, WinMain, or DllMain 
allowed. Previously found main at module.d(3)






I would like to launch function "interestingFunction()" 
directly using rdmd.

Is it possible to achieve that by any way?





I tried to launch the whole file, but it gave me some weird 
output:

C:\Users\User\Desktop\Environment variables>rdmd module.d
OPTLINK (R) for Win32  Release 8.00.17
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
OPTLINK : Warning 134: No Start Address


If you are trying to test a function separately from other 
functions, e.g. for testing, then you are approaching unit 
testing.
You could write a unit test block just under the function to test 
like

unittest
{
  interestingFunction;
}

and launch it via rdmd... don't know the syntax right now. But 
here is something:

https://stackoverflow.com/questions/10694994/rdmd-is-not-running-unit-tests

So, I assume something like
rdmd -unittest --main module.d


Is it possible to execute a function inside .d script that has no main function?

2019-07-11 Thread BoQsc via Digitalmars-d-learn

Here I have a file named: module.d


import std.stdio   : writeln;

void interestingFunction(){
writeln("Testing");
}


There is no main() function since, I want to import this module, 
into another .d file.


( If I try to import and module.d does have main() function I get 
this error: )
otherFile.d(13): Error: only one main, WinMain, or DllMain 
allowed. Previously found main at module.d(3)






I would like to launch function "interestingFunction()" directly 
using rdmd.

Is it possible to achieve that by any way?





I tried to launch the whole file, but it gave me some weird 
output:

C:\Users\User\Desktop\Environment variables>rdmd module.d
OPTLINK (R) for Win32  Release 8.00.17
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
OPTLINK : Warning 134: No Start Address