Output multiple values inside functionCode metadata (C++)

23 views
Skip to first unread message

Tias

unread,
Nov 7, 2015, 5:08:02 AM11/7/15
to Haxe
Hi,

does anyone know how I could write a function in Haxe using the @:functionCode meta that's equivalent to the C++ function below? Or is there an easier alternative to modify multiple values from within a meta?

// C++
void modifyParams(float& a, float& b) {
   a
= a * 2;
   b
= b + 1;
}

// Haxe
class Foo {
   
@:functionCode("
      // ???
   "
)
   
public static function modifyParams(a:Float, b:Float):Void {
     
// How do I modify a and b?
   
}
}


Hugh

unread,
Nov 16, 2015, 12:31:02 AM11/16/15
to Haxe
You can to this with extern classes - but even then you have to be careful because haxe will generate temporary variables - and if you modify these instead of the real variable.  You can do this, though:
class Test
{
   
public static function main()
   
{
     
var x = 10.0;
      modify
( cpp.Pointer.addressOf(x) );
      trace
(x);
   
}

   
public static function modify(xRef:cpp.Pointer<Float>)
   
{
      xRef
.ref = 20.0;
   
}
}


Hugh
Reply all
Reply to author
Forward
0 new messages