Pārlūkot izejas kodu

[cpp] Add some NativeGc functions. Add NativeSys.print(ln) that does not require gc/boxing

Hugh 9 gadi atpakaļ
vecāks
revīzija
74824c7876
3 mainītis faili ar 29 papildinājumiem un 0 dzēšanām
  1. 14 0
      std/cpp/Finalizable.hx
  2. 10 0
      std/cpp/NativeGc.hx
  3. 5 0
      std/cpp/NativeSys.hx

+ 14 - 0
std/cpp/Finalizable.hx

@@ -0,0 +1,14 @@
+package cpp;
+
+// This is just a helper class.  You do not actually need to inherit from this to use
+//  NativeGc.addFinalizable(this,inPin), you just need a function called "finalize"
+class Finalizable
+{
+   public function new(inPin = false)
+   {
+      NativeGc.addFinalizable(this,inPin);
+   }
+
+   public function finalize():Void { }
+}
+

+ 10 - 0
std/cpp/NativeGc.hx

@@ -8,5 +8,15 @@ extern class NativeGc
    @:native("_hx_allocate_extended") @:templatedCall
    static public function allocateExtended<T>(cls:Class<T>, size:Int) : T return null;
 
+   @:native("_hx_add_finalizable")
+   public static function addFinalizable( instance:{ function finalize():Void; }, inPin:Bool ): Void {}
+
+   @:native("hx::InternalNew")
+   public static function allocGcBytesRaw( inBytes : Int, isContainer:Bool ): RawPointer<cpp.Void> return null;
+
+   inline public static function allocGcBytes( inBytes : Int ): Pointer<cpp.Void>
+   {
+      return Pointer.fromRaw( allocGcBytesRaw(inBytes, false) );
+   }
 }
 

+ 5 - 0
std/cpp/NativeSys.hx

@@ -3,6 +3,11 @@ package cpp;
 @:buildXml('<include name="${HXCPP}/src/hx/libs/std/Build.xml"/>')
 extern class NativeSys
 {
+   @:native("__hxcpp_print")
+   public static function print( v : Dynamic ) : Void { }
+
+   @:native("__hxcpp_println")
+   public static function println( v : Dynamic ) : Void { }
 
    @:extern @:native("_hx_std_get_env")
    public static function get_env(v:String) : String return null;