lua-users home
lua-l archive

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


On Sun, May 12, 2013 at 11:06 AM, Harley Laue
<losinggeneration@gmail.com> wrote:
> On Sat, May 11, 2013 at 5:35 AM, Alexander Gladysh <agladysh@gmail.com>
> wrote:
>>
>> On Fri, May 10, 2013 at 7:02 PM, Harley Laue <losinggeneration@gmail.com>
>> wrote:
>> > [1] > math.randomseed(os.time()+assert(tonumber(tostring({}):sub(7))))
>>
>> NB: that sub(7) is not portable — tostring({}) output differs between
>> Lua implementations. Use gsub() to filter out numerics instead. (And
>> even then it is a brittle hack, relying on unspecified behaviour.)

> I agree it's brittle and may fail unexpectedly in the future. The assert is
> there to catch it when it does.  That said, 5.0 (with a change in
> syntax[1]), 5.1 (lua & luajit), and 5.2 all return the same thing for
> tostring with a table as a parameter.

Lua on Windows does not prefix pointer address with 0x, this will
break tonumber(). (You can specify base explicitly as an alternative
to gsub.)

Alexander.