Browse Source

Rework cpp.Function as an abstract so it can be @callable

Hugh 8 years ago
parent
commit
c5589ab6a7
2 changed files with 24 additions and 18 deletions
  1. 7 6
      src/generators/gencpp.ml
  2. 17 12
      std/cpp/Function.hx

+ 7 - 6
src/generators/gencpp.ml

@@ -1617,7 +1617,7 @@ and tcpp_to_string_suffix suffix tcpp = match tcpp with
    | TCppRawPointer(constName,valueType) -> constName ^ (tcpp_to_string valueType) ^ "*"
    | TCppRawPointer(constName,valueType) -> constName ^ (tcpp_to_string valueType) ^ "*"
    | TCppFunction(argTypes,retType,abi) ->
    | TCppFunction(argTypes,retType,abi) ->
         let args = (String.concat "," (List.map tcpp_to_string argTypes)) in
         let args = (String.concat "," (List.map tcpp_to_string argTypes)) in
-        "::cpp::Function< " ^ abi ^ " " ^ (tcpp_to_string retType) ^ "(" ^ args ^ ") >"
+        "::cpp::Function< " ^ (tcpp_to_string retType) ^ " " ^ abi ^ " (" ^ args ^ ") >"
    | TCppObjCBlock(argTypes,retType) ->
    | TCppObjCBlock(argTypes,retType) ->
         (tcpp_objc_block_struct argTypes retType) ^ "::t"
         (tcpp_objc_block_struct argTypes retType) ^ "::t"
    | TCppDynamicArray -> "::cpp::VirtualArray" ^ suffix
    | TCppDynamicArray -> "::cpp::VirtualArray" ^ suffix
@@ -2241,10 +2241,11 @@ let cpp_template_param path native =
    let path = "::" ^ (join_class_path_remap (path) "::" ) in
    let path = "::" ^ (join_class_path_remap (path) "::" ) in
    if (native) then
    if (native) then
       path
       path
-   else if (path="::Array") then
-      "hx::ArrayBase"
-   else
-      path
+   else match path with
+   | "::Array" -> "hx::ArrayBase"
+   | "::Int" -> "int"
+   | "::Bool" -> "bool"
+   | x -> x
 ;;
 ;;
 
 
 
 
@@ -2506,7 +2507,7 @@ let retype_expression ctx request_type function_args expression_tree forInjectio
                  )
                  )
                end
                end
 
 
-            | FStatic ( _, ({cf_name="::cpp::Function_obj::fromStaticFunction"} as member) ) ->
+            | FStatic ( _, ({cf_name="nativeFromStaticFunction"} as member) ) ->
                let funcReturn = cpp_member_return_type ctx member in
                let funcReturn = cpp_member_return_type ctx member in
                let exprType = cpp_type_of member.cf_type in
                let exprType = cpp_type_of member.cf_type in
                CppFunction( FuncFromStaticFunction, funcReturn ), exprType
                CppFunction( FuncFromStaticFunction, funcReturn ), exprType

+ 17 - 12
std/cpp/Function.hx

@@ -19,34 +19,39 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  * DEALINGS IN THE SOFTWARE.
  */
  */
- package cpp;
+package cpp;
 
 
-@:coreType @:structAccess @:include("cpp/Pointer.h")
-extern class Function<T,ABI:cpp.abi.Abi>
+typedef FunctionData<T,ABI> = T;
+
+
+@:include("cpp/Pointer.h") @:callable
+extern abstract Function<T, ABI:cpp.abi.Abi>( FunctionData<T,ABI> )
 {
 {
-   public function new(d:Dynamic);
+   inline public function new(inValue:T) this = inValue;
+
+   // Legacy Api
+   public var call(get,never):T;
+   inline function get_call():T return this;
 
 
-   // Actually a function pointer, but can be called using haxe notation
-	public var call(default,null):T;
 
 
    @:native("::cpp::Function_obj::getProcAddress")
    @:native("::cpp::Function_obj::getProcAddress")
-   static function nativeGetProcAddress<T,ABI:cpp.abi.Abi>(inModule:String, inFunction:String) : AutoCast;
+   @:extern static function nativeGetProcAddress<T,ABI:cpp.abi.Abi>(inModule:String, inFunction:String) : AutoCast return null;
    inline public static function getProcAddress<T,ABI:cpp.abi.Abi>(inModule:String, inFunction:String) : Function<T,ABI>
    inline public static function getProcAddress<T,ABI:cpp.abi.Abi>(inModule:String, inFunction:String) : Function<T,ABI>
    {
    {
       return cast nativeGetProcAddress(inModule, inFunction);
       return cast nativeGetProcAddress(inModule, inFunction);
    }
    }
 
 
    @:native("::cpp::Function_obj::fromStaticFunction")
    @:native("::cpp::Function_obj::fromStaticFunction")
-   static function nativeFromStaticFunction<T>(inStaticFunction:T) : AutoCast;
+   @:extern static function nativeFromStaticFunction<T>(inStaticFunction:T) : AutoCast return null;
    inline public static function fromStaticFunction<T>(inStaticFunction:T) : Callable<T>
    inline public static function fromStaticFunction<T>(inStaticFunction:T) : Callable<T>
    {
    {
       return cast nativeFromStaticFunction(inStaticFunction);
       return cast nativeFromStaticFunction(inStaticFunction);
    }
    }
 
 
-	public function lt(inOther:Function<T,ABI>):Bool;
-	public function leq(inOther:Function<T,ABI>):Bool;
-	public function gt(inOther:Function<T,ABI>):Bool;
-	public function geq(inOther:Function<T,ABI>):Bool;
+	@:extern public function lt(inOther:Function<T,ABI>):Bool return false;
+	@:extern public function leq(inOther:Function<T,ABI>):Bool return false;
+	@:extern public function gt(inOther:Function<T,ABI>):Bool return false;
+	@:extern public function geq(inOther:Function<T,ABI>):Bool return false;
 }
 }