[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Why does #{nil, "sun"} output 2, whereas a={}; a[2]="sun"; print(#a) output 0?
- From: 孙世龙 sunshilong <sunshilong369@...>
- Date: Mon, 12 Oct 2020 14:47:55 +0800
Sorry, hit send too early. Was going to say here:
> a[1] == b[1] --output: true
> a[2] == b[2] --output: true
> a == b --output: false amazing!!!
It's amazing that both "a[1]==b[1]" and "a[2]==b[2]" return "true" whereas
"a==b" returns "false".
Best regards
Sunshilong
On Mon, Oct 12, 2020 at 2:38 PM 孙世龙 sunshilong <sunshilong369@gmail.com> wrote:
>
> Hi, list
>
> Here are the first code snippet and the output:
> >a={nil, "sun"} --output: 2
>
> Here are the second code snippet and the output:
> >b = {}
> >b[2] = "sun"
> >print(#b) --output:0
>
> Here are the third code snippet and the output:
> > function printTab(tab)
> >> for k,v in pairs(tab) do
> >> print(k,v)
> >> end
> >> end
> >
> >type(a) == type(b) --output:true
> >a == b --output: false amazing!!!
> >> printTab(a) --output: 2 sun
> >> printTab(b) --output: 2 sun
>
>
> It's amazing that "printTab(a)" and "printTab(b)" are the same whereas
> "#a" and "#b" are different (and "a == b" outputs false).
> Could somebody shed some light on this question?
>
> Best regards
> Sunshilong