Either I'm just too stupid, or D is lacking something

Wolfgang Draxinger wdraxinger at darkstargames.de
Mon Jul 24 15:53:10 PDT 2006


X-Post to digitalmars.D due to language enhancement suggestion.

Tom S wrote:

> class Foo {
> mixin Mixer!(int, GL_TEXTURE_MIN_FILTER) min_filter_;
> alias min_filter_.foo min_filter;
> }

That's line to much. Otherwise I could also write

template GLTextureParameterI_Set(GLenum Param)(T value) {
glTexParameteri(Target, Param, value);
return value;
}

template GLTextureParameterI_Get(GLenum Param)() {
GLint value;
glGetTexParameteri(Target, Param, &value);
return value;
}

class Foo
{
        mixin GLTextureParameterI_Set(GL_TEXTURE_MIN_FILTER) min_filter;
        mixin GLTextureParameterI_Get(GL_TEXTURE_MIN_FILTER) min_filter;
};

My idea would have been, to extend the declaration of Templated
with something resembling marco unfolding without introducing
it's problems.

I'd like to write e.g the following (note the '#' indicating,
that the template parameter "name" is to be literally replaced
by what is written at the respective point in the template
instanciation. The rule would be, that what follows after a '#'
in a template must be a valid identifier and not a statement or
expression. The usage of such a parameter within a template
declaration would automatically limit it's usage to mixins;
implicit mixin expansion could be assumed, but I'd discourage
that):

template GLTexParameter(T type, GLenum Param, #name)
{
        T #name(T value)
        {
                static if ( is ( T == GLint ) ) {
                        glTexParameteri(Target, Param, value);
                } else static if ( is ( T == GLfloat ) ) {
                        glTexParameterf(Target, Param, value);
                }
                return value;
        }

        T #name()
        {
                T value;
                static if ( is ( T == GLint ) ) {
                        glGetTexParameteriv(Target, Param, &value);
                } else static if ( is ( T == GLfloat ) ) {
                        glGetTexParameterfv(Target, Param, &value);
                }
                return value;
        }
}

class Texture
{
        mixin GLTexParameter!(GLint, GL_TEXTURE_MIN_FILTER, min_filter);
        mixin GLTexParameter!(GLint, GL_TEXTURE_MAG_FILTER, mag_filter);
        mixin GLTexParameter!(GLfloat, GL_TEXTURE_PRIORITY, priority);
/*...*/
}

I used a '#' since it is not being assumed a token by the D specs
right now. I'd also like '$' like in shell scripts or Perl, but
that's a D token already, but right now I can't remember what it
is for, or if it's actually used.

> btw, does your engine have some place in the net ? i'd be
> curious to see it :)

There's nothing to be seen outstanding right now (except some
simple screenshots of single objects), because it's not done
yet. I switched to D, since I got sick with C++ during
development. Ever tried to make self reflecting components in
C++, _with_ template support?

D is a great language for this OTOH for a few reasons: It's easy
to parse. There exists a good frontend for GCC and it delivers
all data that is needed for self reflection.

About one year ago I was looking around for nicer methods on
implementing it, which was, when I came to D.

Rest assured, that as soon the engine is done I'm going to
announce it's release on the D newsgroups.

Check http://www.darkstargames.de/ and if you don't want to loose
your eyes for eye cancer better do it in about 2 months and then
go directly to http://www.darkstargames.de/even ;-) In about a
week the semester break begins and I got 3 months worth of time
to spend only my private projects, which one of them is to make
a new XHTML compliant homepage with sane CSS and modern look.

Wolfgang Draxinger
-- 
E-Mail address works, Jabber: hexarith at jabber.org, ICQ: 134682867




More information about the Digitalmars-d-learn mailing list