Module:LuaCall: Difference between revisions

From Test Wiki
Content deleted Content added
Removing false comment and more commented out code
Removing unused local functions
Line 52: Line 52:
--[[
--[[
------------------------------------------------------------------------------------
------------------------------------------------------------------------------------
-- ipairsAtOffset
-- ipairsAt

--
-- This is an iterator for arrays. It can be used like ipairs, but with
-- This is an iterator for arrays. It can be used like ipairs, but with
-- specified i as first index to iterate.
-- specified i as first index to iterate. i is an offset from 1
--
-- for i,v in p.ipairsAt(t, 3) do body end
--
-- will iterate over the pairs (3,t[3]),(4,t[4]),..., up to the first
-- integer key absent from the table.
--
-- Note: The following is an example to do range iteration from 3 to j
--
-- for i,v in p.ipairsAt(t, 3) do if i>j then break end; body end
--
------------------------------------------------------------------------------------
--]]
local function ipairsAt(t, i)
--return ipairsAtOffset(t, i-1)
-- This may be less overhead than return ipairsAtOffset() above
local f, s, i0 = ipairs(t)
return f, s, i0+i-1
end

--[[
------------------------------------------------------------------------------------
-- ipairsAtOffset
--
-- Like ipairsAt(), except that it treat argument i as offset from 1
--
--
------------------------------------------------------------------------------------
------------------------------------------------------------------------------------
Line 87: Line 63:
return f, s, i0+i
return f, s, i0+i
end
end

local function iIteratorsAtOffset(t, i)
local f, s, i0 = ipairs(t)
return function (s, i)
local i, v = f(s, i); return v
end, s, i0+i
end

-- like ipairs() except that it return only value, rather than key/value pair
-- on each iteration
local function iIterators(t) return iIteratorsAtOffset(t, 0) end


local function get(s)
local function get(s)