Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

haxe

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?

like image 219
SMKS Avatar asked Sep 30 '15 20:09

SMKS


1 Answers

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

like image 90
Justo Delgado Avatar answered Nov 13 '22 23:11

Justo Delgado