I am currently playing around in writing PHP externs for the Processwire API (ProcessWire API Reference - ProcessWire API). But when for example starting with the Page
class you encounter something like that:
In addition to the methods and properties above, Page also inherits the methods and properties of these classes:
- WireData
- Wire
Typical problem (especially when writing externs for js, btw) since Haxe Externs supports single inheritance only. Also no Traits, mixins or whatever.
But actually I found a way to solve that. tink_lang Partials to the rescue. Checkout this example:
@:tink interface Wire {
function someWireFunction(): Void {};
}
@:tink interface WireData {
var somewireData: String;
}
extern class Page implements Wire implements WireData {
function doSomething();
}
class Test {
static function main() {
var instance = new Page();
instance.doSomething();
instance.someWireFunction();
trace(instance.somewireData);
}
}`
I am surprised, but this actually works. Thank you very much @back2dos
Reason for this posts are 2:
First I wanted to share that tipp, because I was struggling quite a bit to get those kind of externs right.
But to be honest I am not sure if this is just clever… or “hacky”. I don’t even think tink_lang partials
were intended to be used that way. So I would love to get some opinion. Is it “save” to do it that way?
Wonder if we maybe get some built in solution in Haxe4 for something like this.