请教一个Lua新手问题
书上说lua的table作为数组,其索引最好是以1开始,并有许多机制依赖于此。
请问长度操作符#(返回最后一个元素的索引)是否与这个有关?
请看下面代码:
a = {}
for ia = 5,11 do
a[ia] = ia
end
print('#a=' .. #a)
print('==================')
b = {}
for ib = 5,12 do
b[ib] = ib
end
print('#b=' .. #b)
print('===================')
c = {}
for ic = 4,11 do
c[ic] = ic
end
print('#c=' .. #c)
print('===================')
lua
#a=0
==================
#b=0
===================
#c=11
===================