Bladeren bron

[cpp] Trick haxe into thinking that cpp.Function class is callable

Hugh 9 jaren geleden
bovenliggende
commit
835cd5243d
2 gewijzigde bestanden met toevoegingen van 12 en 13 verwijderingen
  1. 8 3
      src/generators/gencpp.ml
  2. 4 10
      std/cpp/Callable.hx

+ 8 - 3
src/generators/gencpp.ml

@@ -1655,7 +1655,8 @@ let rec cpp_type_of ctx haxe_type =
       cpp_instance_type ctx klass params
 
    | TAbstract (abs,pl) when abs.a_impl <> None ->
-       cpp_type_of ctx (Abstract.get_underlying_type abs pl)
+       cpp_type_from_path ctx abs.a_path pl (fun () -> 
+            cpp_type_of ctx (Abstract.get_underlying_type abs pl) )
 
    | TAbstract (a,params) ->
        cpp_type_from_path ctx a.a_path params (fun () -> cpp_type_of ctx (follow haxe_type) )
@@ -1707,6 +1708,8 @@ let rec cpp_type_of ctx haxe_type =
             TCppRawPointer("const ", cpp_type_of ctx p)
       | (["cpp"],"Function"), [function_type; abi] ->
             cpp_function_type_of ctx function_type abi;
+      | (["cpp"],"Callable"), [function_type] ->
+            cpp_function_type_of_string ctx function_type "";
 
       | ([],"Array"), [p] ->
          let arrayOf = cpp_type_of ctx p in
@@ -1752,6 +1755,8 @@ let rec cpp_type_of ctx haxe_type =
                  | TInst (klass1,_) -> get_meta_string klass1.cl_meta Meta.Abi
                  | _ -> assert false )
       in
+      cpp_function_type_of_string ctx function_type abi
+   and cpp_function_type_of_string ctx function_type abi_string =
       match follow function_type with
       | TFun(args,ret) ->
           (* Optional types are Dynamic if they norally could not be null *)
@@ -1761,9 +1766,9 @@ let rec cpp_type_of ctx haxe_type =
              else
                 cpp_type_of ctx haxe_type
           in
-          TCppFunction(List.map cpp_arg_type_of args, cpp_type_of ctx ret, abi)
+          TCppFunction(List.map cpp_arg_type_of args, cpp_type_of ctx ret, abi_string)
       | _ ->  (* ? *)
-          TCppFunction([TCppVoid], TCppVoid, abi)
+          TCppFunction([TCppVoid], TCppVoid, abi_string)
 
    and cpp_instance_type ctx klass params =
       cpp_type_from_path ctx klass.cl_path params (fun () ->

+ 4 - 10
std/cpp/Callable.hx

@@ -19,15 +19,12 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  */
- package cpp;
+package cpp;
 
-#if cpp
 
-typedef Callable<T> = Function<T, cpp.abi.Abi >
-
-#else
-
-@:noPackageRestrict
+// The generator intercepts this type and converts it to a cpp.Function<T> on cpp
+@:noPackageRestrict @:callable
+#if cpp extern #end
 abstract Callable<T>(T)
 {
    public var call(get,never):T;
@@ -38,6 +35,3 @@ abstract Callable<T>(T)
 }
 
 
-#end
-
-