www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to get name of my application (project)

reply Andrey <saasecondbox yandex.ru> writes:
Hello, how to get name of my application (project) that we write 
in dub.json? Is there any compile-time constant like __MODULE__?
Aug 03 2019
next sibling parent reply =?UTF-8?B?UsOpbXkgTW91w6t6YQ==?= <remy.moueza gmail.com> writes:
On Saturday, 3 August 2019 at 09:26:03 UTC, Andrey wrote:
 Hello, how to get name of my application (project) that we 
 write in dub.json? Is there any compile-time constant like 
 __MODULE__?
If I understand the question correctly, you are looking for std.file.thisExePath: - http://dpldocs.info/experimental-docs/std.file.thisExePath.html - https://dlang.org/phobos/std_file.html#thisExePath
Aug 03 2019
parent reply Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Saturday, August 3, 2019 5:47:33 AM MDT Rmy Mouza via Digitalmars-d-
learn wrote:
 On Saturday, 3 August 2019 at 09:26:03 UTC, Andrey wrote:
 Hello, how to get name of my application (project) that we
 write in dub.json? Is there any compile-time constant like
 __MODULE__?
If I understand the question correctly, you are looking for std.file.thisExePath: - http://dpldocs.info/experimental-docs/std.file.thisExePath.html - https://dlang.org/phobos/std_file.html#thisExePath
Also, the first element in the array passed to main is the name of the executable. - Jonathan M Davis
Aug 03 2019
parent Jacob Carlborg <doob me.com> writes:
On 2019-08-03 17:58, Jonathan M Davis wrote:

 Also, the first element in the array passed to main is the name of the
 executable.
No, what's passed to "main" is the path to however the application was invoked, not the executable. If you invoke it as "./foo" it will pass "./foo" to the "main" function. If you invoke it as "/usr/local/bin/foo" it will pass "/usr/local/bin/foo" to the "main" function. That's at least how it works on macOS. "thisExePath" will give you the full path to the executable regardless how if it was invoked. It will resolve symlinks as well. So it depends on what's needed. "name of application" is a bit diffuse statement. -- /Jacob Carlborg
Aug 05 2019
prev sibling next sibling parent Bastiaan Veelo <Bastiaan Veelo.net> writes:
On Saturday, 3 August 2019 at 09:26:03 UTC, Andrey wrote:
 Hello, how to get name of my application (project) that we 
 write in dub.json? Is there any compile-time constant like 
 __MODULE__?
The name of an application is not a compile time constant: you can rename the executable at any time. Like Rémy said, thisExePath.baseName will get you the name at run time. Bastiaan.
Aug 03 2019
prev sibling next sibling parent drug <drug2004 bk.ru> writes:
03.08.2019 12:26, Andrey пишет:
 Hello, how to get name of my application (project) that we write in 
 dub.json? Is there any compile-time constant like __MODULE__?
You can get it using $DUB_PACKAGE from Environment variables (https://dub.pm/package-format-sdl), for example using preBuildCommands you can generate a module and define the constant you need there.
Aug 03 2019
prev sibling parent James Blachly <james.blachly gmail.com> writes:
On 8/3/19 5:26 AM, Andrey wrote:
 Hello, how to get name of my application (project) that we write in 
 dub.json? Is there any compile-time constant like __MODULE__?
Dear Andrey: Perhaps this is similar to what you are looking for: https://dlang.org/spec/grammar.html#SpecialKeyword SpecialKeyword: __FILE__ __FILE_FULL_PATH__ __MODULE__ __LINE__ __FUNCTION__ __PRETTY_FUNCTION__ These are available at compile time. Kind regards.
Aug 03 2019