I'm currently making a system, since I need to identify too many things as nil or {}, I'm looking for a way like this:
local lorem, ipsum, dolor, sit = {}, {}, {}, {}
I will do it, but how many words I can identify in 1 local?
I'm currently making a system, since I need to identify too many things as nil or {}, I'm looking for a way like this:
local lorem, ipsum, dolor, sit = {}, {}, {}, {}
I will do it, but how many words I can identify in 1 local?
Lua has a hard-coded limit which can be found in lparser.c from the Lua source files:
/* maximum number of local variables per function (must be smaller
than 250, due to the bytecode format) */
#define MAXVARS 200
That is, any function can have at most 200 local variables declared within it, regardless of how many local declarations are used.
This sounds and looks like an X/Y question so my main question back would be why, but I'll bite.
You can do at most 200 variables, because by empirical testing, Lua only allows you to have 200 local variables to any piece of code.
(Note that judging by a comment here, it may seem that the limit is actually supposed to be 256 local variables. This was tested on Lua for Windows. Your mileage may wary apparently.)
And yes, you can declare and give them all a value using just 1 local declaration.
local aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an,ao,ap,aq,ar,as,at,au,av,aw,ax,ay,az,ba,bb,bc,bd,be,bf,bg,bh,bi,bj,bk,bl,bm,bn,bo,bp,bq,br,bs,bt,bu,bv,bw,bx,by,bz,ca,cb,cc,cd,ce,cf,cg,ch,ci,cj,ck,cl,cm,cn,co,cp,cq,cr,cs,ct,cu,cv,cw,cx,cy,cz,da,db,dc,dd,de,df,dg,dh,di,dj,dk,dl,dm,dn,dp,dq,dr,ds,dt,du,dv,dw,dx,dy,dz,ea,eb,ec,ed,ee,ef,eg,eh,ei,ej,ek,el,em,en,eo,ep,eq,er,es,et,eu,ev,ew,ex,ey,ez,fa,fb,fc,fd,fe,ff,fg,fh,fi,fj,fk,fl,fm,fn,fo,fp,fq,fr,fs,ft,fu,fv,fw,fx,fy,fz,ga,gb,gc,gd,ge,gf,gg,gh,gi,gj,gk,gl,gm,gn,go,gp,gq,gr,gs,gt,gu,gv,gw,gx,gy,gz,ha,hb,hc,hd,he,hf,hg,hh,hi,hj,hk,hl,hm,hn,ho,hp,hq,hr,hs=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200
print(aa)
print(ab)
print(ac)
print(ad)
print(ae)
print(af)
print(ag)
print(ah)
print(ai)
print(aj)
print(ak)
print(al)
print(am)
print(an)
print(ao)
print(ap)
print(aq)
print(ar)
print(as)
print(at)
print(au)
print(av)
print(aw)
print(ax)
print(ay)
print(az)
print(ba)
print(bb)
print(bc)
print(bd)
print(be)
print(bf)
print(bg)
print(bh)
print(bi)
print(bj)
print(bk)
print(bl)
print(bm)
print(bn)
print(bo)
print(bp)
print(bq)
print(br)
print(bs)
print(bt)
print(bu)
print(bv)
print(bw)
print(bx)
print(by)
print(bz)
print(ca)
print(cb)
print(cc)
print(cd)
print(ce)
print(cf)
print(cg)
print(ch)
print(ci)
print(cj)
print(ck)
print(cl)
print(cm)
print(cn)
print(co)
print(cp)
print(cq)
print(cr)
print(cs)
print(ct)
print(cu)
print(cv)
print(cw)
print(cx)
print(cy)
print(cz)
print(da)
print(db)
print(dc)
print(dd)
print(de)
print(df)
print(dg)
print(dh)
print(di)
print(dj)
print(dk)
print(dl)
print(dm)
print(dn)
print(dp)
print(dq)
print(dr)
print(ds)
print(dt)
print(du)
print(dv)
print(dw)
print(dx)
print(dy)
print(dz)
print(ea)
print(eb)
print(ec)
print(ed)
print(ee)
print(ef)
print(eg)
print(eh)
print(ei)
print(ej)
print(ek)
print(el)
print(em)
print(en)
print(eo)
print(ep)
print(eq)
print(er)
print(es)
print(et)
print(eu)
print(ev)
print(ew)
print(ex)
print(ey)
print(ez)
print(fa)
print(fb)
print(fc)
print(fd)
print(fe)
print(ff)
print(fg)
print(fh)
print(fi)
print(fj)
print(fk)
print(fl)
print(fm)
print(fn)
print(fo)
print(fp)
print(fq)
print(fr)
print(fs)
print(ft)
print(fu)
print(fv)
print(fw)
print(fx)
print(fy)
print(fz)
print(ga)
print(gb)
print(gc)
print(gd)
print(ge)
print(gf)
print(gg)
print(gh)
print(gi)
print(gj)
print(gk)
print(gl)
print(gm)
print(gn)
print(go)
print(gp)
print(gq)
print(gr)
print(gs)
print(gt)
print(gu)
print(gv)
print(gw)
print(gx)
print(gy)
print(gz)
print(ha)
print(hb)
print(hc)
print(hd)
print(he)
print(hf)
print(hg)
print(hh)
print(hi)
print(hj)
print(hk)
print(hl)
print(hm)
print(hn)
print(ho)
print(hp)
print(hq)
print(hr)
print(hs)
Outputs all the numbers from 1 through 200.
Add 1 variable to this, and at least Lua for windows gives this error:
C:\Program Files (x86)\Lua\5.1\lua.exe: test.lua:1: main function has more than 200 local variables
local xx = 0 at the end of the above script and it fails with the exact same error message, except for the line number involved. Downloaded and installed from here. I notice that lua.org is up to 5.4, but the link on lua binaries for Lua for Windows points to this 5.1 version. Perhaps someone needs to update something?