title: What can i do to address a parent in lua?
body: <p>I am making a game, and in it the player needs to spawn some bullets:</p>
  
  <pre><code>game
  ├──player = {}
  └──bullets = {}
  </code></pre>
  
  <p>I've heard in godot you can use <code>parent</code> to address the parent node and wonder if i can imitate that somehow.</p>
  
  <p>I currently have 2 potential solutions:</p>
  
  <pre><code>local game = {
      player = player.new(x, y, spawnBullet),
      bullets = {}
  }
  </code></pre>
  
  <p><code>spawnBullet</code> being a function. Although that would require doing that for all functions, which might be annoying.</p>
  
  <p>My second solution would be to pass game iteslf to the player</p>
  
  <pre><code>local game
  game = {
      player = player.new(x, y, game),
      bullets = {},
  </code></pre>
  
  <p>And in <code>player.new(x, y, parent)</code></p>
  
  <pre><code>player.parent = parent
  </code></pre>
  
  <p>Are these solutions all there is available or are there better ones?</p>
  
  <p>Whatever, I made a node module myself.</p>
  
  <pre class="lang-lua prettyprint-override"><code>local node = {}
  node.__index = node
  
  local new = function(name, parent)
      assert(name, "Please provide a name for the node")
      local newNode = {
          name = name,
          parent = parent,
      }
      return setmetatable(newNode, node)
  end
  
  return setmetatable(
      {
          new = new,
          __call = new,
      },
      node
  )
  </code></pre>