Search code examples
haxe

Does Haxe pass parameters by reference or does it make a copy?


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?


Solution

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