lua-users home
lua-l archive

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


> > Nice. You may want to try adding a proxy table as in my lgdbm so that
> > you can write t[k]=v and update the database, and t[k] to query it.
> 
> Yes, it is on my TODO list to provide a Lua-style interface to the
> database. The question remains on how/whether to handle other class methods
> efficiently in __index, since I want to use it for "t[k]".

That's where *proxy* comes in. You create an empty table that redirects
to the db handle. Something like this:

function db_proxy(db)
 local m= {
	__index=function (t,k) return db:get(k) end,
	__newindex=function (t,k,v) db:set(k,v) end
	}
 return setmetatable({},m)
end

You can also add __pairs calling db:cursor, etc.