lua-users home
lua-l archive

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


On 31/08/2011, at 7:36 AM, Alexander Gladysh wrote:

> No, as I understand it, whole function must be pairs-free for this to
> work. Maybe I'm wrong, that's a wild guess. (You may try to move the
> loop to a separate function to try this hypothesis.)

That doesn't seem to be the case:

test.lua:

local function a()
  local t = {}
  for i = 1, 100000 do
    t[i] = i
  end
  
  local ps, is = 0, 0
  for _, v in pairs(t) do
    ps = ps + v
  end

  for _, v in ipairs(t) do
    is = is + v
  end

  return ps, is
end

print(a())

--

$ luajit -jdump test.lua 
...
---- TRACE 3 start test.lua:12

That is, a trace was started at line 12 - the start of the ipairs loop  (What I don't understand in this case is why a trace was never even attempted for the pairs loop)

Cheers,
Geoff