lua-users home
lua-l archive

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



> Would this change from Lua 5.1 apply to "for k,v in <function> do end" and other variations of 'for' as well or just to the version with numeric limits?

Both forms of 'for':

Lua 5.1 (work)  Copyright (C) 1994-2004 Tecgraf, PUC-Rio
> f = {}
> for k, v in _G do table.insert(f, function() return k.." is a "..type(v) end) end
> table.sort(f, function(a, b) return a() < b() end)
> for _, fn in ipairs(f) do print(fn()) end
_G is a table
_LOADED is a table
_TRACEBACK is a function
_VERSION is a string
__pow is a function
assert is a function
collectgarbage is a function
coroutine is a table
debug is a table
...

--------------------------
(current version:)
Lua 5.0.2  Copyright (C) 1994-2004 Tecgraf, PUC-Rio
> f = {}
> for k, v in _G do table.insert(f, function() return k.." is a "..type(v) end) end
> table.sort(f, function(a, b) return a() < b() end)
stdin:1: attempt to concatenate a nil value
stack traceback:
        stdin:1: in function `a'
        stdin:1: in function <stdin:1>
        [C]: in function `sort'
        stdin:1: in main chunk
        [C]: ?
>