[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Question about Lua 5.1.3 and realloc() on life.lua
- From: "Eric Tetz" <erictetz@...>
- Date: Thu, 1 May 2008 14:44:36 -0700
Bogdan Marinescu wrote:
> I ran 'life.lua', and the results surprised me. Specifically, I can see lots
> and lots of realloc calls with a one byte difference between the old block
> size and the new block size, in both directions (+1 or -1 difference).
Replace _CELLS:draw() with:
function _CELLS:draw()
local out={} -- accumulate to reduce flicker
for y=1,self.h do
for x=1,self.w do
out[#out + 1] = self[y][x] > 0 and ALIVE or DEAD
end
out[#out + 1] = '\n'
end
write(table.concat(out))
end
Mike Pall wrote:
> This is not a recommended practice and hopefully not representative for
> professionally written Lua programs.
When Lua is used as an end-user scripting language, a lot of Lua code
is *not* written by professionals. There are hundreds of World of
Warcraft addons with code just as bad as that loop in life.lua. *sigh*
Cheers,
Eric