I'm not sure how, but we managed to create a table with two keys in exactly the same way. When we execute a forcycle on a pairstable and print keys and values, we get:
1 true
1 true
and we thought it was a question of different types or something else, so we decided to convert it to json (we use the Corona SDK and the internal json module).
The result was very striking:
"ourTable" : { "1" : true, "1" : true }
We saved it in a file to check the values, and both hexadecimal values "1"were 31.
So, another test: convert this json to a lua table and ... the same result as before: two records with the same key.
I had never seen anything like this before, and to be honest, I don’t know how to detect and prevent such a situation. We have been using lua and corona for several years, and for the first time we discovered something similar, but it is possible that this happened earlier, and we did not find it. This may lead to unexpected results.
Corona SDK uses Lua 5.1.
We store this json table encoded in a file. After restarting the application, the file loaded again and contained only one entry! Now ... this table contained only "id" and boolean, both values are exactly the same, but I wonder what will happen if the values are different, and what remains? Tons of scripts come to my mind now.
I cannot reproduce this problem, but what we do:
- Read file using json
- Json decoding to lua table
- / ,
tab[key] = value
EDIT:
, , :
local d = {true}
d["1"]=true
for k,v in pairs(d) do
print(k,v)
end
1 true
1 true