Browse Source

[cpp] Fix casting for names with spaces in them. Add some helpers for interacting with external functions

hughsando 10 năm trước cách đây
mục cha
commit
e55fe73219
4 tập tin đã thay đổi với 34 bổ sung3 xóa
  1. 1 1
      gencpp.ml
  2. 13 0
      std/cpp/CastCharStar.hx
  3. 13 0
      std/cpp/ConstCharStar.hx
  4. 7 2
      std/cpp/Lib.hx

+ 1 - 1
gencpp.ml

@@ -2404,7 +2404,7 @@ and gen_expression ctx retval expression =
       gen_expression ctx retval cast;
    | TCast (cast,None) ->
       let ret_type = type_string expression.etype in
-      output ("( " ^ ret_type ^ "(");
+      output ("((" ^ ret_type ^ ")(");
       gen_expression ctx true cast;
       output "))";
    | TCast (e1,Some t) ->

+ 13 - 0
std/cpp/CastCharStar.hx

@@ -0,0 +1,13 @@
+package cpp;
+
+abstract CastCharStar( RawPointer<Char> ) to(RawPointer<Char>)
+{
+   inline function new(s:String) this = untyped s.__s;
+
+   @:from
+   static public inline function fromString(s:String) return new CastCharStar(s);
+
+    @:to
+    public inline function toPointer() return this;
+}
+

+ 13 - 0
std/cpp/ConstCharStar.hx

@@ -0,0 +1,13 @@
+package cpp;
+
+abstract ConstCharStar( RawConstPointer<Char> ) to(RawConstPointer<Char>)
+{
+   inline function new(s:String) this = untyped s.__s;
+
+   @:from
+   static public inline function fromString(s:String) return new ConstCharStar(s);
+
+    @:to
+    public inline function toPointer() return this;
+}
+

+ 7 - 2
std/cpp/Lib.hx

@@ -25,12 +25,17 @@ package cpp;
 import haxe.macro.Context;
 import haxe.macro.Type;
 import haxe.macro.Expr;
-#end
+#else
 
 using cpp.NativeString;
 using cpp.RawConstPointer;
 using cpp.Char;
 
+#end
+
+#if macro
+@:noPackageRestrict
+#end
 class Lib {
 
    #if !macro
@@ -142,7 +147,7 @@ class Lib {
          case "s" : return "String";
          case "o" : return "cpp.Object";
          case "v" : return "cpp.Void";
-         case "c" : return "cpp.RawConstPtr<cpp.Char> ";
+         case "c" : return "cpp.ConstCharStar";
          default:
             throw "Unknown signature type :" + code;
       }