[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [BUG]Lua function args bug
- From: "Mark Meijer" <meijer78@...>
- Date: Wed, 10 Dec 2008 16:41:00 +0100
Doh... Yes, I see now. Thanks!
2008/12/7 Peter Cawley <firstname.lastname@example.org>:
> table.foreach passes the key (1) and the value ("2") of each entry in the
> table to the function. Hence print(1, "2") is called, with the 1 coming from
> the table index, not from the f argument - for example, bind(5, "2") still
> prints 1 2 from foreach.
> On Sun, Dec 7, 2008 at 12:45 PM, Mark Meijer <email@example.com> wrote:
>> Perhaps I'm dense. I ran the OP's example and got the same result,
>> then I changed the table.foreach loop into the for k,v in pairs(args)
>> variant, and it worked as expected. Clearly you guys understand why,
>> but I don't see it. Could someone please explain?
>> 2008/12/6 Miles Bader <firstname.lastname@example.org>:
>> > "pan shizhu" <email@example.com> writes:
>> >> It is quite normal to use table.foreach and made this kind of mistake.
>> >> I
>> >> think this might be the reason to obsolete table.foreach. Please note
>> >> that
>> >> table.foreach is officially obsoleted. Use for k,v in pairs(table)
>> >> instead,
>> >> which is less prone for mistake.
>> > Using "for" is better for code, but table.foreach is often more
>> > convenient for interactive use.
>> > -Miles
>> > --
>> > Love is a snowmobile racing across the tundra. Suddenly it flips over,
>> > pinning you underneath. At night the ice weasels come. --Nietzsche