www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - imports in a Separate File?

reply Ron Tarrant <rontarrant gmail.com> writes:
I ran across a code example 
(https://github.com/gtkd-developers/GtkD/blob/master/demos/gtkD/Test
indow/TestWindow.d) in which the first ~120 lines are mostly import statements.

And it got me wondering...

I tried to off-load a bunch of imports into a pseudo-header file 
— importedStuff.d — and then in the actual code file I just did:

import importedStuff;

but found myself swimming in undefined identifier errors.

Is there a way to do this so I wouldn't have to scroll 120 lines 
into a file before finding code? Or does this mean I still 
haven't caught onto what I was told the last time I was on this 
forum?

(And here's a grammar question, just for the heck of it: Why 
isn't forum spelled with an 'n,' like column?)
Dec 11 2018
parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
On 12/11/18 10:27 AM, Ron Tarrant wrote:
 I ran across a code example 
 (https://github.com/gtkd-developers/GtkD/blob/master/demos/gtkD/Test
indow/TestWindow.d) 
 in which the first ~120 lines are mostly import statements.
 
 And it got me wondering...
 
 I tried to off-load a bunch of imports into a pseudo-header file — 
 importedStuff.d — and then in the actual code file I just did:
 
 import importedStuff;
 
 but found myself swimming in undefined identifier errors.
 
 Is there a way to do this so I wouldn't have to scroll 120 lines into a 
 file before finding code? Or does this mean I still haven't caught onto 
 what I was told the last time I was on this forum?
 
 (And here's a grammar question, just for the heck of it: Why isn't forum 
 spelled with an 'n,' like column?)
 
Use public imports in your header file. This will pretend that the symbols imported reside in the module itself. i.e. inside importedStuff.d: public { // 120 import statements } -Steve
Dec 11 2018
parent Ron Tarrant <rontarrant gmail.com> writes:
On Tuesday, 11 December 2018 at 15:39:18 UTC, Steven 
Schveighoffer wrote:

 Use public imports in your header file. This will pretend that 
 the symbols imported reside in the module itself.

 i.e. inside importedStuff.d:

 public {
    // 120 import statements
 }

 -Steve
Thanks, Steve. Works like a charm... but you knew that.
Dec 11 2018