class A
{
string getName(this Klass)()
{
return Klass.stringof;
}
}
class B : A
{}
void main()
{
import std.stdio;
auto a = new A;
auto b = new B;
writeln(a.getName());
writeln(b.getName());
}
##
This
tl;dr - how to get child classname from inherited parent function
at compile time?
class A { string getName(); };
class B { };
B foo = new B;
assert(foo.getName() == B);
...
Hi! I'm stuck at one issue, and I don't know how to solve it. I
think this is about mixins/templates, isn't it?
When
I found a rough solution. It's not ideal and I still want to make
autoinject, but it works.
mixin template Manager(T) {};
class Component {};
class Sprite:Component
{
mixin Manager!Sprite;
};
1) How to make mixin inject automatic?
2) If it's impossible, how to use mixin Manager; without
On Thursday, 21 August 2014 at 12:58:13 UTC, MarisaLovesUsAll
wrote:
I found a rough solution. It's not ideal and I still want to
make autoinject, but it works.
mixin template Manager(T) {};
class Component {};
class Sprite:Component
{
mixin Manager!Sprite;
};
1) How to make mixin inject
On Thursday, 21 August 2014 at 13:19:06 UTC, anonymous wrote:
1) How to make mixin inject automatic?
You could use this pattern:
interface Component {}
class ComponentImpl(T) {}
class Sprite : ComponentImpl!Sprite {}
From my view, it's an architectural crutch. %)
You can use `typeof(this)`
On 8/21/14, 6:38 AM, MarisaLovesUsAll wrote:
tl;dr - how to get child classname from inherited parent function at
compile time?
class A { string getName(); };
class B { };
B foo = new B;
assert(foo.getName() == B);
...
Hi! I'm stuck at one issue, and I don't know how to solve it. I think
this
On Thursday, 21 August 2014 at 19:58:18 UTC, MarisaLovesUsAll
wrote:
When I make mixin injection in one class, I want auto-injection
in another class. How can I do this?
class Component:GameObject
{
//second injection must be here and must be automatic
};
class Sprite:Component
{
On Thursday, 21 August 2014 at 20:05:13 UTC, Ary Borenszweig
wrote:
I'll tell you how it's done in Crystal in case someone wants to
come up with a proposal to make it work in D.
~~~
class Foo
macro inherited
def method_in_{{@class_name.downcase.id}}
puts Hello {{@class_name.id}}!
On Thursday, 21 August 2014 at 20:16:33 UTC, anonymous wrote:
Maybe you can explain what you're trying to achieve with all
this. There may be a different/better way to do it.
Sure.
Class tree: GameObject-Component-Sprite.
GameObject structure:
Component[];
Component