lua-users home
lua-l archive

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


On Fri, Dec 20, 2013 at 2:04 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
2013/12/20 Sir Pogsalot <sir.pogsalot@gmail.com>:

> 3) I'm missing something obvious that makes this a bad idea.
+1

The following pieces of code so the same.

> setmetatable(a,{__pairs=tbl})
> for k,v in pairs(a) do print(k,v) end
> for k,v in pairs(tbl) do print(k,v) end


Hmm, I do not understand why that is bad :3  I'm not sure why you would do that, but if that is your intention... you can still a['read'] and a['write'] = 'to' the table `a', you just iterate over something else.  It would be the same as if you had done: setmetatable(a, { __pairs = function () return pairs(tbl) end })