6

Take this code:

function createGUIHud():Void
{
    this.screen.gameHud = new NormalGameHud(10, 0, this.screen.getTextureAtlas());
    this.screen.gameHud.x = FlxG.width - (this.screen.gameHud.width + GameSize.getPositionByPlatform(10));
    this.screen.gameHud.y = GameSize.getPositionByPlatform(10);
}

// NormalGameHud.hx

public function new(lives:Int = 10, corn:Int = 0, textureAtlas:SparrowData) 
{
    super(0, 0, 30);
    this.lives = lives;
    this.cornCount = corn;
    this.textureAtlas = textureAtlas;

    this.createScoreboard();
    this.createLivesCount();
    this.createCornCounter();
}

Does textureAtlas get passed by reference or does it get copied?

I know PHP passes objects by reference, and things like Arrays get copied unless stated otherwise (prefixed with &). Does the same apply with Haxe?

Gama11
  • 31,714
  • 9
  • 78
  • 100
SMKS
  • 179
  • 1
  • 4
  • 13

1 Answers1

5

AFAIK, Basic Types (Int, Float, Bool) are passed by value. Everything else is passed by reference.

Gama11
  • 31,714
  • 9
  • 78
  • 100
Justo Delgado
  • 534
  • 2
  • 5
  • 5
    "Primitives" can be considered are passed by reference too. It is just they are immutable which means by ref/value does not even matter. – Andy Li Sep 30 '15 at 22:42
  • 1
    Actually, I would say that everything in Haxe is passed by value, where basic types (Bool, Int, Float) are copied directly where as objects and other types have their references copied. Bool, Int, Float and String are always immutable and compared by value. Whether or not Strings are copied or have their references copied I think is target specific, but as they are immutable it doesn't really matter. – Jonas Malaco Oct 05 '15 at 23:04