title: Lua metatable, how to forward undefined functions?
body: <p>I have an empty table which I want to act as a "gateway" to another set of functions at another location.</p>
  
  <pre><code>tbl = {}
  </code></pre>
  
  <p>I want to pass called functions from this table to somewhere else as a string:</p>
  
  <pre><code>tbl.someMethod("hello")
  </code></pre>
  
  <p>I've tried this with limited success.</p>
  
  <pre><code>hand = {
      __index = function(tbl, name)
        hand[name] = function(...) 
            passToSomewhere(name, ...)
        end
      end,
      __call = function(tbl, name, ...)
          hand[name](...)
      end
  }
  setmetatable(tbl, hand)
  tbl.someFunction("hello!", someTbl, someNumber)
  </code></pre>
  
  <p>How do I forward the undefined function through the table without it throwing errors?</p>
  
  <p>Edit: More detail</p>
  
  <p>I'm trying to define and call a function in a table in one call:</p>
  
  <pre><code>tbl = {}
  
  hand = {
    __index = function(tbl, name)
      print(name)
      tbl[name] = function(...)
        print(...)
      end
    end
  }
  setmetatable(tbl, hand)
  
  s,e = pcall(tbl.help,"banana","goat")
  print(s)
  
  s,e = pcall(tbl.help,"banana","goat")
  print(s)
  </code></pre>
  
  <p>This code does work but the first pcall will throw an error because the function hasn't been defined yet.</p>
  
  <p>Say I wanted to use an library which I know updates quite a lot and keep my script compatible and this library may not be present on my computer. I would like to forward calls to this library across some interface but I still want to be able to call the functions in the same way.</p>
  
  <pre><code>--For example I would like to call this function like this:
  someLib.doSomething(name, age, telephone)
  
  --Instead of passing it through another function:
  someOtherLib.invoke("someLib.doSomething", name, age, telephone)
  </code></pre>
  
  <p>Is this possible?</p>
  
  <p>Edit 2:</p>
  
  <p>Thanks @greatwolf !</p>
  
  <p>This is my working test code.</p>
  
  <pre><code>tbl = {}
  
  hand = {
    __index = function(tbl, name)
      tbl[name] = function(...)
        return print(name, ...)
      end
      return rawget(tbl, name) 
    end
  }
  setmetatable(tbl, hand)
  
  tbl.help("banana","goat")
  </code></pre>