Răsfoiți Sursa

[cppia] Export numeric types in a compatible type to what the runtime expects

Closes #8502
Caue Waneck 6 ani în urmă
părinte
comite
1f4bdf6568

+ 3 - 1
src/generators/gencpp.ml

@@ -5385,11 +5385,13 @@ let script_type t optional = if optional then begin
    | _ -> "Object"
    | _ -> "Object"
    end else match type_string t with
    end else match type_string t with
    | "bool" -> "Int"
    | "bool" -> "Int"
-   | "int" -> "Int"
+   | "int" | "::cpp::Int32" -> "Int"
    | "Float" -> "Float"
    | "Float" -> "Float"
    | "::String" -> "String"
    | "::String" -> "String"
    | "Null" -> "Void"
    | "Null" -> "Void"
    | "Void" -> "Void"
    | "Void" -> "Void"
+   | "float" | "::cpp::Float32" | "::cpp::Float64" -> "Float"
+   | "::cpp::Int64" | "::cpp::UInt64" -> "Object"
    | _ -> "Object"
    | _ -> "Object"
 ;;
 ;;
 
 

+ 42 - 0
tests/unit/src/scripthost/Issue8502.hx

@@ -0,0 +1,42 @@
+package scripthost;
+#if cpp
+
+@:keep class Issue8502 {
+	public function new() {
+		//initialize variables
+	}
+
+	public function doTest1(f:cpp.Float32):String {
+		return '$f';
+	}
+
+	public function doTest2(f:cpp.Float64):String {
+		return '$f';
+	}
+
+	public function doTest3(f:cpp.Int8):String {
+		return '$f';
+	}
+
+	public function doTest4(f:cpp.Int16):String {
+		return '$f';
+	}
+
+	public function doTest5(f:cpp.Int32):String {
+		return '$f';
+	}
+
+	public function doTest3u(f:cpp.UInt8):String {
+		return '$f';
+	}
+
+	public function doTest4u(f:cpp.UInt16):String {
+		return '$f';
+	}
+
+	public function doTest5u(f:cpp.UInt32):String {
+		return '$f';
+	}
+}
+
+#end

+ 52 - 0
tests/unit/src/unit/issues/Issue8502.hx

@@ -0,0 +1,52 @@
+package unit.issues;
+#if cpp
+
+class Issue8502 extends Test {
+  public function test() {
+		var t:scripthost.Issue8502 = Type.createInstance(Type.resolveClass('unit.issues.Issue8502_2'), []);
+    eq(t.doTest1(25), 'cppia 25');
+    eq(t.doTest2(25), 'cppia 25');
+    eq(t.doTest3(25), 'cppia 25');
+    eq(t.doTest4(25), 'cppia 25');
+    eq(t.doTest5(25), 'cppia 25');
+    eq(t.doTest3u(25), 'cppia 25');
+    eq(t.doTest4u(25), 'cppia 25');
+    eq(t.doTest5u(25), 'cppia 25');
+  }
+}
+
+class Issue8502_2 extends scripthost.Issue8502 {
+	override public function doTest1(f:cpp.Float32):String {
+		return 'cppia ' + super.doTest1(f);
+	}
+
+	override public function doTest2(f:cpp.Float64):String {
+		return 'cppia ' + super.doTest2(f);
+	}
+
+	override public function doTest3(f:cpp.Int8):String {
+		return 'cppia ' + super.doTest3(f);
+	}
+
+	override public function doTest4(f:cpp.Int16):String {
+		return 'cppia ' + super.doTest4(f);
+	}
+
+	override public function doTest5(f:cpp.Int32):String {
+		return 'cppia ' + super.doTest5(f);
+	}
+
+	override public function doTest3u(f:cpp.UInt8):String {
+		return 'cppia ' + super.doTest3u(f);
+	}
+
+	override public function doTest4u(f:cpp.UInt16):String {
+		return 'cppia ' + super.doTest4u(f);
+	}
+
+	override public function doTest5u(f:cpp.UInt32):String {
+		return 'cppia ' + super.doTest5u(f);
+	}
+}
+
+#end