lua-users home
lua-l archive

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


>What happens in Lua 5.2 if you type to the standalone interpreter:
>
>       for k,v in ipairs"Hello, World!" do print(k,v) end
>
>(a) bad argument #1 to 'ipairs' (table expected, got string)
>(b) attempt to index a string value
>(c) an infinite loop
>(d) nothing
>(e) depends on which minor release you are running
>(f) none of the above

>And in Lua 5.3?

Here's what I observed:

In Lua 5.2:

$ lua52
Lua 5.2.4  Copyright (C) 1994-2015 Lua.org, PUC-Rio
> for k,v in ipairs"Hello, World!" do print(k,v) end
stdin:1: bad argument #1 to 'ipairs' (table expected, got string)
stack traceback:
        [C]: in function 'ipairs'
        stdin:1: in main chunk
        [C]: in ?
>
>os.exit()

In Lua 5.3:

$ lua53
Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio
> for k,v in ipairs"Hello, World!" do print(k,v) end
>
>os.exit()