is there a way to: import something = app-xyz-classes-something; ?
Steven Schveighoffer
schveiguy at gmail.com
Mon Jun 21 13:29:59 UTC 2021
On 6/21/21 4:55 AM, frame wrote:
> On Monday, 21 June 2021 at 03:32:58 UTC, someone wrote:
>> Since memory serves I use to name files with - instead of the more
>> common _
>
> The module name has to be strict and "-" is not allowed.
> However, you should be able to import files with a "-" in the name.
>
> From the manual:
>
>> If the file name of a module is an invalid module name (e.g.
>> foo-bar.d), you may use a module declaration to set a valid module name:
>
>
> ```d
> module foo_bar;
> ```
>
> Tested on Windows/dmd - does NOT work :(
It does work. However, you have to tell the compiler the file to compile.
When an import is used, the compiler does 2 stages:
1. Search through already-seen modules, and see if one matches
2. Search the filesystem to find a file that fits the module name. For
example `std.path` becomes `$INCLUDE_DIR/std/path.d`
So if you provide the file name to the compiler as part of the set of
files to compile, it should work. e.g:
foo-bar.d:
```d
module foo_bar;
```
app.d:
```d
module app;
import foo_bar;
void main () {}
```
compiled like:
```
> dmd app.d foo-bar.d
```
That being said, I strongly recommend just to name the file the same as
the module name.
-Steve
More information about the Digitalmars-d-learn
mailing list