|
On Sat, May 11, 2013 at 5:35 AM, Alexander Gladysh <agladysh@gmail.com> wrote:
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.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.)
Alexander.
[1] Lua 5.0 requires it to be changed to sub(tostring({}), 7) instead of tostring({}):sub(7) I just liked the later syntax and I don't care about supporting 5.0 because it's for personal use and I don't use 5.0.