[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: write a list of variables to a file, formatted
- From: Philippe Lhoste <PhiLho@...>
- Date: Thu, 27 Jun 2013 10:50:01 +0200
On 26/06/2013 21:53, Eike Decker wrote:
As pointed out before by Thijs Schreijer, wrapping arguments into tables causes trouble
when nil values are around. Besides, nonstring values can also be problematic with concat.
I am not sure, but the code I wrote should handle both cases correctly.
Lua 5.2.0 Copyright (C) 1994-2011 Lua.org, PUC-Rio
> f = function () return 1, 2, nil, 3, 4 end
> print(f())
1 2 nil 3 4
> print(table.concat(table.pack(f()), " "))
stdin:1: invalid value (nil) at index 3 in table for 'concat'
stack traceback:
[C]: in function 'concat'
stdin:1: in main chunk
[C]: in ?
> print(table.concat({ f() }, " "))
stdin:1: invalid value (nil) at index 3 in table for 'concat'
stack traceback:
[C]: in function 'concat'
stdin:1: in main chunk
[C]: in ?
Non-string values are fine, but nil is indeed a showstopper...
Your wrapper, Eike, takes care nicely of the problem (and nil can be ignored or changed to
something specific, too).
Note that print() doesn't separate with spaces but with tabs.
--
Philippe Lhoste
-- (near) Paris -- France
-- http://Phi.Lho.free.fr
-- -- -- -- -- -- -- -- -- -- -- -- -- --