[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Is Lua the next big thing?
- From: "Kristofer Karlsson" <kristofer.karlsson@...>
- Date: Thu, 15 Mar 2007 13:24:47 +0100
2007/3/15, Philippe Lhoste <PhiLho@gmx.net>:
Sam Roberts wrote:
> Lua is scheme-minimalist in many ways, but one thing the lisps have
> usually provided (always?) is data marshalling. You can write and
> read recursive data structures natively. I know, there are dozens of
> implementations of this out there for lua... but maybe thats a bad
> thing.
That's funny, I just updated my DumpObject script, to sport a nicer
(more compact) representation of empty table. I also corrected a bug
(non-matching quotes in tostring output for functions and other special
data).
http://lua-users.org/wiki/PhilippeLhoste
Not that anybody care, but hey! :-D
I had to write a small function to test if a table is empty. Did I miss
something more straightforward? I recall some discussions around this
point, but not the final word on the topic...
function IsTableEmpty(t)
local c = 0
for k, v in pairs(t) do c = c + 1 end
return c == 0
end
My script is still in Lua 5.0 (works fine in Lua 5.1 too).
--
Philippe Lhoste
-- (near) Paris -- France
-- http://Phi.Lho.free.fr
-- -- -- -- -- -- -- -- -- -- -- -- -- --
The simplest way to check if a table is empty is probably this:
function IsTableEmpty(t) return not next(t) end
Of course, the negated function is much easier to define:
function IsTableNotEmpty = next