lua-users home
lua-l archive

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

I just realized that table.foreach and its cousin wasn't quite as 
complete as I would like. I thought someone might find these simple, 
(somewhat tested) extensions useful. (No guarantee that it works blah 
blah blah don't sue me if it screws up your system)

ext = {}

-- foreach that can have extra arguments
function ext.foreach (tbl, f, ...)
   table.foreach(tbl, function (i,v) f(i,v,unpack(arg)) end)

-- foreach for methods with extra args
function ext.mforeach(tbl,m,...)
   table.foreach(tbl,function (i,v) m(v,unpack(arg)) end)

-- foreachi with extra args
function ext.foreachi (tbl, f, ...)
   table.foreachi(tbl,function (i,v) f(i,v,unpack(arg)) end)

-- foreachi for methods with extra args
function ext.mforeachi(tbl,m,...)
   table.foreachi(tbl,function (i,v) m(v,unpack(arg)) end)

David Hall
den uparchei kanena koutali