lua-users home
lua-l archive

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


On Sat, Dec 21, 2013 at 8:53 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
I don't see why one needs a patch for that. It is easy enough in plain
Lua. 

Yes, you can do this in plain Lua.  This patch is about matching what __newindex/__index allows -- a table or function assignment to the __pairs/__ipairs (metafield?).  Currently a table assignment errors (as you said) when it would make sense to me to allow either and just recall pairs/ipairs on the table if it's not a function.  My hope was that because this is a 4-line patch, it would not be seen as feature bloat and would also be seen as expected behavior since this is what __newindex/__index lets you do.

As you said earlier, it does not result in a big win for execution speed, but it does save a sizable chunk of memory by not defining redundant functions like this:

__pairs = function () return pairs(other_table) end

(for when metatables are not shared)