mherkender/lua.js

Affecting to a table seems to erase other values

slurdge opened this issue · 3 comments

Example code:

test = {4,1,2}
print(test[1],test[2],test[3])
test[2] = 3
print(test[1],test[2],test[3])

Prints:

4 1 2
null 3 null

I think this comes from the autoIndexList.
The keys are taken as "string". In Firefox&Chrome:

>>> for (var i in [1,2,3]){console.log(typeof i);}
string
string
string

I fixed it by putting the following in ensure_notarraymode:

      if (table.uints[i] != null) {
        //if i is a string cast it to int
        newuints[i - 0 + 1] = table.uints[i];
      }

That's pretty serious. I'll check it out when I have a moment.

Thanks for the report, you're right about the cause of this bug. It's been fixed with f59409c.