title: Inheritance in Lua
body: <p>I am trying to make a simple api that eases the process of creating classes and sub-classes.</p>
  
  <pre><code>function newClass(index,...)
    local new_class = {}
  
    setmetatable(new_class,{__index = index})
  
    local optionalArgs = {...}
    if optionalArgs[1] ~= nil then
        setmetatable(new_class,optionalArgs[1])
    end
  
    return new_class
  
  end
  
  --TESTINGCODE
  exampleSuper = newClass({name="Super",id=1,getName = function() print("Super") end,})
  exampleSuper.getName()
  exampleSub = newClass({name="Sub",},exampleSuper)
  print(exampleSub.id)
  </code></pre>
  
  <p>The problem is that even though I create a new super class called exampleSuper, it's fields aren't given to the exampleSub class. How can I change my code to allow my function to define a sub class?</p>