[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Is string always same as number? (the consistency of lua)
- From: Xavier Wang <weasley.wx@...>
- Date: Thu, 10 Feb 2011 13:45:53 +0800
hi all.
as we know, lua has eight types: nil, bool, number, string, function, table, userdata and thread.
in Lua, nil and false are (nearly) the same. as number and string are (nearly) the same. but we know, nil is not false, false means "not true", but nil means "nothing".
but, what is number and string?
in perl, number and string are the same. they are "scalar", so we can use number in the place using string, and vice versa. this is just the meanings of the words “number and string are the same".
but in lua, the number and string is not "exactly" the same. e.g. in table index, the number and string is different. that means:
local t = {}
t['1'] = 1
t['2'] = 2
table.remove(t, '1')
can not delete the "1" entry in table. because this is a string key.
Is this behave normal for Lua? in lua, '1' + 1 = 2, but in table index they are diffierent.
maybe we can make all number-like string table index all number, is that more consistency?
btw, is consistency the one of goals of Lua?