title: Extend lua-resty-* modules and call parent function
body: <p>I am trying to write for each <a href="https://github.com/openresty/lua-resty-redis/" rel="nofollow">lua-resty-redis</a>, <a href="https://github.com/openresty/lua-resty-memcached" rel="nofollow">lua-resty-memcached</a> and <a href="https://github.com/openresty/lua-resty-mysql" rel="nofollow">lua-resty-mysql</a> modules a small class that extends the default module. In my child class, I want to call a function from the parent class but couldn't find a proper way no matter what inheritance documentation for Lua I've read.</p>
  
  <p>For example, I want to overwrite the <code>connect()</code> function, do some stuff and call the parent's <code>connect()</code> function at some point. But how?</p>
  
  <pre><code>local redis = require "resty.redis"
  
  
  function redis.connect(self, ...)
  
  
    -- Do some stuff here
  
  
    local ok, err = parent:connect(...)
  
  
    -- Do some other stuff here
  
  
    return ok, err
  end
  </code></pre>
  
  <p>How can this be achieved?</p>
  
  <p>As a note, all the above mentioned modules are structured like this:</p>
  
  <pre><code>local _M = { _VERSION = "0.1" }
  
  local mt = { __index = _M }
  
  function _M.new(self)
      return setmetatable({ foo = "bar" }, mt)
  end
  
  function _M.connect(self, ...)
      -- Connect
  end
  
  return _M
  </code></pre>
  
  <p>Thank you in advance!</p>