Python externs

Hi there,
It’s been a long time…
My wife recently offered a “vector”, a little cute robot that i can program.
Sadly the only SDK available is in Python.

Here is a litle piece of code i want to do in Haxe

import anki_vector


def main():
    args = anki_vector.util.parse_command_args()
    with anki_vector.Robot(args.serial) as robot:
        robot.behavior.say_text("haxe power")


if __name__ == "__main__":
    main()

And this is my miserable attempt

class Main {
    static public function main():Void {
      trace("Hello World");
      var robot = new Robot();
    }
  }

@:pythonImport("anki_vector")
@:native("anki_vector.Robot")
extern class Robot {
  public function new();
}

My problem is that the generated code doesn’t import the anki_vector as i want.

import anki_vector as anki_vector_Robot

any help will be appreciated :pensive:

Doing

@:pythonImport("anki_vector.Robot")
extern class Robot {
  public function new();
}

gives me import anki_vector.Robot as Robot, that should work I guess.

Thank you Valention but it doesn’t work

ModuleNotFoundError: No module named 'anki_vector.Robot'

Then it seems Robot is not a module then.

This might work: (I assumed serial was a boolean, might not be)

class Main {
	static public function main():Void {
		var robot = AnkiVector.Robot(false);
		robot.behavior.say_text("haxe power");
	}
}

@:pythonImport("anki_vector")
@:native("anki_vector")
extern class AnkiVector {
	public static function Robot(serial:Bool):Robot;
}

extern class Robot {
	public var behavior:Behavior;
}

extern class Behavior {
	public function say_text(msg:String):Void;
}

Note that in python the with probably calls some dispose function or something at the end of the block that’s not done here.