How do I specify platform-specific versions of an extern class?

(Thomas J Webb) #1

I haven’t seen any actual guidance on this and looking at how Kha does it, for example, is non-standard (using its own make system not simply hxml files). I also see in haxe itself’s std, there are platform-specific versions under _std (for example Array.hx) but this seems to be part of haxe’s own specific build process, separate from how one would build a lib.

I have an extern class that I want to map to the native class in the appropriate platforms:

extern class MidiIn
    public function new();
    public function getPorts():Array<String>;
    public function openPort(portNumber:Int, portName:String):Void;
    public function openVirtualPort(portName:String):Void;
    public function closePort():Void;
    public function isPortOpen():Bool;
    public function setCallback(callback:(MidiMessage, Float)->Void):Void;
    public function cancelCallback():Void;

This lives inside of its own lib ( Then I have a non-extern version in a separate lib specifically for python externs (grig-python):

class MidiIn
// ...

Before I added dependencies from the former lib (grig.midi), I could build and run no problem because it was just treated as a normal class. But now that I have two separate classes with the same name under the same module path, there is no MidiIn class in the final python output:

haxe tests.hxml -python bin/ && python bin/
spits out a bunch of crap and
NameError: name 'grig_midi_MidiIn' is not defined

And I can confirm in there is no class with the name MidiIn or that ends in that whatsoever. Curious that there’s no error on the haxe side, only upon running in python.

What’s the right way to do this? Am I barking up the wrong tree? There are a number of things I need to make platform specific externs for like this.


If I do this in reverse and specify -lib grig-python from grig.midi, it works. I’ll have to see how it works when I have a project that links to both. Will it know where to get the class from?


I settled on using typedefs for now.