mherkender / lua.js

An ECMAscript framework to compile and run Lua code, allowing Lua to run in a browser or in Flash
http://blog.brokenfunction.com/
600 stars 73 forks source link

Affecting to a table seems to erase other values #7

Closed slurdge closed 12 years ago

slurdge commented 12 years ago

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
slurdge commented 12 years ago

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];
      }
mherkender commented 12 years ago

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

mherkender commented 12 years ago

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