RealyUniqueName / haxe

Haxe - The Cross-Platform Toolkit

Home Page:http://haxe.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pass by reference type

benmerckx opened this issue · comments

commented

Implemented for function arguments only in 829e225

In some instances there's a need to pass a value by reference (it's needed to implement some array methods).
It might be interesting to allow something like this:

function test(v: Reference<String>): Reference<String> {
  return v;
}

To compile to:

function &test(&$v) {
  return $v;
}

Or alternatively use metadata to achieve the same.

@:reference function test(@:reference v: String): String {
  return v;
}

I agree that ability to pass value by reference is absolutely must have. Third-party php code may use it, so Haxe->PHP should support it.

For that purpose i think special extern class is preferable because.

  • it's not obvious such meta works for php target only
  • metas are not listed in automatically generated documentation

Myabe that Class should be called php.Ref<T> since other similar types in Haxe std lib are usually called Ref

commented

Sure, php.Ref<T> (php7.Ref<T>) seems most logical.

After some thinking i've decided to handle references only for function arguments.
Handling return by reference requires too much hacking in generator for such a rare use-case.

Implemented for function arguments only in 829e225