Passing table (playerObject) to an other table, is this only a reference?

I have a playerObject which has several functions and variables in it’s table.

In the spawn function of the playerObject I call createBlockingObject (my own function) where I pass the name of the playerObject so when a NPC catches the blockingObject it can see what the name of the player was by looking at the blockingObject.playerName.

It works fine but what if I wanna reach more variables or execute functions on the player?

Could I instead of only passing the playerObject’s name variable, just pass the whole playerObject (self)?

For example if there are 30 blocking objects, will it affect the memory alot? or is passing the “self” of the playerObject just a reference to the table?

Just in case anyone is interested in an answer to this question, the answer is that it’s perfectly fine to pass on object along to another.  This is what makes objects so nice to work with.  I assume your setup is something is similar to this:

Player object factory (player.lua):

[lua]

local player = {}

function player.new( player_data )

  local playerObj = {}

  playerObj.playerName = player_data.player_name

  playerObj:getPlayerName = function( some_vars )

    return self.playerName

  end

end

return player

[/lua]

Other file (?.lua):

[lua]

local player = require( ‘player’ )

local po = player.new( player_data )

function createBlockingObject( po )

  print( po:getPlayerName() )

  print( po.playerName )

end

[/lua]

Pay extra attention to the colons, as opposed to just a dot, in the calls.  The objects are passed as reference.

Best.

Just in case anyone is interested in an answer to this question, the answer is that it’s perfectly fine to pass on object along to another.  This is what makes objects so nice to work with.  I assume your setup is something is similar to this:

Player object factory (player.lua):

[lua]

local player = {}

function player.new( player_data )

  local playerObj = {}

  playerObj.playerName = player_data.player_name

  playerObj:getPlayerName = function( some_vars )

    return self.playerName

  end

end

return player

[/lua]

Other file (?.lua):

[lua]

local player = require( ‘player’ )

local po = player.new( player_data )

function createBlockingObject( po )

  print( po:getPlayerName() )

  print( po.playerName )

end

[/lua]

Pay extra attention to the colons, as opposed to just a dot, in the calls.  The objects are passed as reference.

Best.