Browse Source

[cpp] all pointers are implemented with cpp.Pointer. Add Pointer.fromPointer. Add way of setting finalizer from haxe.

Hugh 11 years ago
parent
commit
cb576785a8
6 changed files with 13 additions and 5 deletions
  1. 1 1
      gencpp.ml
  2. 2 1
      std/cpp/ConstPointer.hx
  3. 1 1
      std/cpp/Function.hx
  4. 1 2
      std/cpp/NativeString.hx
  5. 2 0
      std/cpp/Pointer.hx
  6. 6 0
      std/cpp/vm/Gc.hx

+ 1 - 1
gencpp.ml

@@ -471,7 +471,7 @@ let is_cpp_function_class haxe_type =
 
 let is_fromStaticFunction_call func =
    match (remove_parens func).eexpr with
-   | TField (_,FStatic ({cl_path=["cpp"],"Function"},{cf_name="fromStaticFunction"} ) ) -> true
+   | TField (_,FStatic ({cl_path=["cpp"],"Pointer"},{cf_name="fromStaticFunction"} ) ) -> true
    | _ -> false
 ;;
 

+ 2 - 1
std/cpp/ConstPointer.hx

@@ -1,8 +1,9 @@
 package cpp;
 
-@:coreType @:include("cpp/Pointer.h")
+@:coreType @:include("cpp/Pointer.h") @:native("cpp.Pointer")
 extern class ConstPointer<T> extends BasePointer<T>
 {
+   public static function fromPointer<T>(inNativePointer:Dynamic) : ConstPointer<T>;
 
 	public function at(inIndex:Int):T;
 

+ 1 - 1
std/cpp/Function.hx

@@ -1,6 +1,6 @@
 package cpp;
 
-@:coreType @:include("cpp/Pointer.h")
+@:coreType @:include("cpp/Pointer.h") @:native("cpp.Pointer")
 extern class Function<T> extends BasePointer<T>
 {
    public static function getProcAddress<T>(inModule:String, inFunction:String) : Function<T>;

+ 1 - 2
std/cpp/NativeString.hx

@@ -3,8 +3,7 @@ package cpp;
 extern class NativeString {
 
 	public static inline function c_str( inString:String ) : ConstPointer<Char> {
-		var result:ConstPointer<Char> =  untyped inString.__s;
-		return result;
+		return cpp.ConstPointer.fromPointer(untyped inString.__s);
    }
 	public static inline function fromPointer(inPtr:ConstPointer<Char> ) : String {
       return untyped __global__.String(inPtr.ptr);

+ 2 - 0
std/cpp/Pointer.hx

@@ -5,6 +5,8 @@ extern class Pointer<T> extends ConstPointer<T> implements ArrayAccess<T>
 {
 	public var ref(get,set):T;
 
+   public static function fromPointer<T>(inNativePointer:Dynamic) : Pointer<T>;
+
    public static function addressOf<T>(inVariable:T) : Pointer<T>;
 
 	public static function arrayElem<T>(array:Array<T>, inElem:Int):Pointer<T>;

+ 6 - 0
std/cpp/vm/Gc.hx

@@ -91,4 +91,10 @@ class Gc
    {
       untyped __global__.__hxcpp_exit_gc_free_zone();
    }
+
+   static public function setFinalizer<T>(inObject:T, inFinalizer:cpp.Function<T->Void> ) : Void
+   {
+      untyped __global__.__hxcpp_set_finalizer(inObject, inFinalizer.ptr);
+   }
 }
+