exception on generic for loop

Issue #6 invalid
mezzodrinker created an issue
> table1 = {1,2,3}; for k,v in table1 do print("hi"); end
Exception: attempt to call a table value
Stack traceback:
        stdin:0: in main chunk
> for k,v in _G do print(k, "->", v); end
Exception: attempt to call a table value
Stack traceback:
        stdin:0: in main chunk

Comments (3)

  1. Chimaine

    That is because you specified table1 and _G as the iterator function.

    for exprList in iterator [[, table], start] do block end

    So that should be

    for i in inext, table1 do print("hi"); end
    
    for k,v in next, _G do print(k, "->", v); end
    

    inext is the list iterator, next is the mapping iterator.

  2. Log in to comment