FLTK native in 'D'. Would that be useful?

Bruno Medeiros brunodomedeirosATgmail at SPAM.com
Sun Jul 30 08:57:51 PDT 2006


John Reimer wrote:
> On Thu, 27 Jul 2006 12:57:56 -0700, MatthiasM <dm at matthiasm.com> wrote:
> 
>> John Reimer wrote:
>>>  I think one improvement would be to drop all Fl_* prefixes on class 
>>> names like FLTK 2.0 does.  I looked and 2.0 and found it world's 
>>> better looking than the older 1.1.
>>>  Is that possible?
>>
>> Yes, that would be possible. I do agree on the looks. My original idea 
>> was to do the port as compatible as possible, so that existing FLTK 
>> apps can be easily ported, which is why I left the original class 
>> names alone.
>>
>> I am still not a hundred percent familiar with the "module" keyword 
>> full names. My first choice would be to map class names like this: 
>> (best of both worlds)
>>
>>    C++:           D:
>>
>>    Fl_Window  ->  fl.Window (or just Window, if no name conflict)
>>    Fl_Group   ->  fl.Group
>>    fl_draw()  ->  fl.draw()
>>
> 
> 
> Yes, that would be a solution.  They are called "renamed imports" and 
> are available as of 0.163. But you would need to do it slightly 
> different with GDC 0.19 which is still based off of 0.162 (or earlier?). 
> Version 0.163 implements an improved import system.  In GDC 0.19, you 
> probably can do the same using "alias" for now.
> 
> 
>> How would I implement this, assuming the fltk path would be for example:
>>
>>    gui/fl/window.d
>>
>> and using
>>
>>    import gui.fl.window;
> 
> 
> Using dmd 0.163, try this:
> 
> # // import all symbols in gui.fl.window module into the 'fl' namespace
> #
> # import fl = gui.fl.window;
> #
> # void main()
> # {
> #     ...
> #     auto win1 = new fl.Window( );
> #     ...
> # }
> 
> 
> Using GDC 0.19 (equivalent to 0.162), I think you can do this for now 
> (next version should support the new import features, though):
> 
> 
> # import gui.fl.window;
> # // rename the module namespace
> # alias gui.fl.window fl;
> #
> # void main()
> # {
> #     ...
> #     auto win1 = new fl.Window();
> #     ...
> # }
> 
> Others might have some more suggestions.  But I think that's an 
> improvement over using Fl_ prefix.
> 
> All the best,
> 
> JJR

But there is a problem with that, it won't work if one wants to import
several gui.fl.* modules.

   import gui.fl.window;
   alias gui.fl.window fl; // rename the module namespace
   import gui.fl.group;
   alias gui.fl.group fl; // <- fl name conflict

There are some particular aspects like these when converting code from a
language with a namespace naming system like C++ (or C#) to D's
package+module system. The best solution I think is to create a "name
forwarding" module that will emulate the fl namespace:

   module gui.fl.flnamespace;

   public import gui.fl.window;
   public import gui.fl.group;
   public import gui.fl.draw;

Usage:

   import gui.fl.flnamespace;
   alias gui.fl.flnamespace fl;

   ...

   fl.Window ...
   fl.Group ...
   fl.draw();

Alternatively you can also redesign the way you structure FLTKs classes
and accesses in D's naming system.

-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d-dwt mailing list