realyuniquename / haxe-traits Goto Github PK
View Code? Open in Web Editor NEW[DEPRECATED] Traits for Haxe
[DEPRECATED] Traits for Haxe
function test() {
var t:Button = cb;
}
Button - unknown type
Seems that if you import an "interface A"(IEntity) that has a variable of type "class B"(EntityData) that has a function with return type "class C"(Entity) and "class C" implements the "interface A", then variables from "interface A" simply aren't copied to "class C" or something like this.
The same if you import "Class C" and then "Interface A".
But no problems for imports "Class C" or "Interface A" and "Class C"
interface TSpeaker extends ITrait {
public function say(msg:String) trace(msg);
}
interface TScreamer extends TSpeaker {
public function scream(msg:String) this.say(msg.toUpperCase() + "!!!!!!");
}
Hello! How may I access (in code) if a class is implementing a specific trait?
For instance:
if (Car.hasTrait(FastEngine)){
Car.DriveFast();
}
I was also just wondering if this is stable enough to use in a full project, thanks! : ) ๐
Edit:Sorry I don't know markdown to make that code look pretty! ๐
interface TListener extends ITrait {
var brain : Brain;
public function update(){
brain.process( listen() );
}
public function listen() : BrainInfo {
/* translate surrounding sounds to info undertandable by brain */
}
}
interface TWatcher extends ITrait {
var brain : Brain;
public function update(){
brain.process( watch() );
}
public function watch() : BrainInfo {
/* translate what i see to info understandable by brain */
}
}
class Human extends Lifeform implements TWatcher, implements TListener {
/**
* This should be auto-generated if `update()` method is not defined by programmer
*/
override public function update(){
super.update();
//this order should reflect `implements` directives order
traits.Trait.parent(TWatcher).update();
traits.Trait.parent(TListener).update();
}
}
Deal with using and such:
using Lambda;
interface TFoo implements ITrait {
function bar(a:Iterable<String>) return a.has("foo");
}
class MyFoo implements TFoo {}
interface TFoo extends ITrait {
/* these expressions should be added to descendant's constructor */
var deg2rad : Float = Math.PI / 180;
var bar : Bar = new Bar();
}
class Foo extends Some implements TFoo {
/**
* This should be auto-generated
*/
public function new() {
super();
this.deg2rad = Math.PI / 180;
this.bar = new Bar();
}
}
Substitute type parameters (tink_lang in fact already does this);
interface TFoo<T> implements ITrait {
function first(a:Iterable<T>):T return a.iterator.next();
}
class MyFoo implements TFoo<Int> {}
:-)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.