lua-users home
lua-l archive

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


On Thu, Jun 30, 2011 at 4:59 AM, steve donovan
<steve.j.donovan@gmail.com> wrote:
> Easy to do efficiently in C (using Lua requires packing and unpacking)

naïve, ends-on-nil version:

function mapvar (f,a,...)
	if a ~= nil then
		return f(a),mapvar(f,...)
	end
end


slightly better:

function mapvar (f,a,...)
	if select('#',...) > 0 then
		return f(a),mapvar(f,...)
	else
		return f(a)
	end
end

-- 
Javier