lua-users home
lua-l archive

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


Steve, there's a bug in "1.13 Why doesn't 'for k,v in t do' work anymore?",
substituting 'print(i,v)' instead of 'print(v)' gives 2,10; 3,20; ...

my fix:

function iter(t)
  local i = 1
  return function()
     local val = t[i]
     if val == nil then return nil end
     local icurrent = i
     i = i + 1
     return icurrent ,val
  end
end

for i,v in iter {10,20,30} do print(i,v) end


(Thanks for the faq)
-- Joe


On Tue, Dec 22, 2009 at 12:09 PM, steve donovan <steve.j.donovan@gmail.com> wrote:
http://www.batbytes.com/luafaq/

Version 1.5 answers a few new questions, like:
1.37 How does module() work?
1.38 What are weak tables?
1.39 What is the difference between the various ways to quote strings?
7.7 What am I allowed to do with the Lua stack and its contents in my
C functions?
7.8 What is the difference between userdata and light userdata?

And generally cleaned up some entries (thanks to spir for pointing out
problem with newproxy example, and Dirk Feytons for new C API
material)

Have a read, and please be picky; this needs to be solid as possible
if people are going to be leaning on it.

steve d.