I am writing a class that I will translate to both Python and C#.
My code uses the nice "glm" library. Glm provides useful datatypes, e.g: Vec3
.
Can I make Vec3
visible to the Python and C# users of my class?
In other words, can I expose public methods using Vec3
datatypes?
Here is a sample Haxe code with a class whose public function uses the Vec3
type:
// Test execution:
// haxe -main TestGLM1 -lib glm --interp
// Translate into Python:
// haxe -main TestGLM1 -python TestGLM1.py -lib glm
// python3 TestGLM1.py
import glm.Vec3;
import glm.Quat;
import glm.Mat4;
class TestGLM1 {
public function new() {
}
static function main() {
// My test of the method taking 3D datatypes as input and output
var t: TestGLM1 = new TestGLM1() ;
var v1: Vec3 = new Vec3(1,2,3) ;
var v2: Vec3 = new Vec3(7,8,9) ;
t.testVecIO(v1, v2);
trace(v1, v2);
}
public function testVecIO(vec_in: Vec3 , vec_out: Vec3) {
vec_out.x = vec_in.x + vec_out.x;
vec_out.y = vec_in.y + vec_out.y;
vec_out.z = vec_in.z + vec_out.z;
}
}
I would like to write a Python test like this:
from TestGLM1 import TestGLM1
from TestGLM1 import glm_Vec3
print("Python Test...")
t = TestGLM1()
v1 = glm_Vec3(1,2,3) # Vec3()
v2 = glm_Vec3(4,5,6) # Vec3()
t.testVecIO(v1, v2)
print(v1, v2)
print("Python done.")
However, this test fails:
ImportError: cannot import name 'glm_Vec3'
because the only class that I can see in TestGLM1.py
is:
class glm_Vec3Base:
_hx_class_name = "glm.Vec3Base"
__slots__ = ("x", "y", "z")
_hx_fields = ["x", "y", "z"]
def __init__(self):
self.z = None
self.y = None
self.x = None
which has both an unfriendly name and doesn't show a proper constructor.
Any advice? Thanks.