lua-users home
lua-l archive

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


Yes, see http://www.lua.org/manual/5.1/manual.html#2.5.5

a={1,2,3,4}
print(#a)	-- 4

The # operator also works for strings.

b="abc" 
print(#b)	-- 3

The # operator also has to do with the 'len' meta method. see
http://www.lua.org/manual/5.1/manual.html#2.8



> -----Original Message-----
> From: lua-bounces@bazar2.conectiva.com.br 
> [mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of 
> Michael Bauroth
> Sent: dinsdag 21 april 2009 10:59
> To: Lua list
> Subject: Re: Accessing "external" tables from within LuaExpat 
> callbacks
> 
> Interesting part! Just one short question: What does the part
> 
> stuff[ #stuff+1 ]
> 
> Is the use of # a official part of Lua for the length of the 
> tablearray?
> 
> Best Regards
> Micha
> 
> 
> Elbers, H.P. schrieb:
> > A smal example:
> > 
> > #!/usr/bin/env lua
> > 
> > require("lxp")
> > local stuff = {}
> > 
> > xmldata="<Top><A/> <B a='1'/> <B a='2'/><B a='3'/><C a='3'/></Top>"
> > 
> > function doFunc(parser, name, attr)
> >   if not (name == 'B') then return end
> >   stuff[#stuff+1]= attr
> > end
> > 
> > local xml = lxp.new{StartElement = doFunc}
> > xml:parse(xmldata)
> > xml:close()
> > 
> > print(stuff[2].a)
> > 
> > ==> 2
> > 
> 
>