lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


	Hi Bertrand

module('connection', package.seeall)

function new(driver)
 local db = {
   driver = driver -- luasql driver type
 }
 -- loads the SQL adapter for the given driver
 local adapter = require("adapter." .. driver)
 for k, v in pairs(adapter) do
   if k ~= "_M" then
     db[k] = v
   end
 end

 setmetatable(db, {__index = _M})
 return db
end
	Why don't you simply:

function new(driver)
  local db = {
    driver = driver -- luasql driver type
  }
  -- loads the SQL adapter for the given driver
  local adapter = require("adapter." .. driver)
  return setmetatable(db, {__index = function(t, k) return _M[k] or adapter[k] end})
end

	Tomás