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

Never add a nil value to a table #30

Closed elisee closed 11 years ago

elisee commented 11 years ago

myTable[key] = nil should never add key/nil to the table's objs, as it's supposed to be used for clearing table-as-dictionary entries.

This pull request fixes that be making sure bFound will always be true if value == null, which will prevent the nil value from being added to the table.

elisee commented 11 years ago

By the way, is there a reason why table.objs is a list [] rather than a dictionary {}?

Looking up object keys is probably much slower than it could be because of that. After a cursory look at the source, I can't see a good reason for that, considering Lua makes no guarantee as to the orders in which key/value pairs are returned when using pairs():

The pairs() function will allow iteration over key-value pairs. Note that the order that items are returned is not defined, not even for indexed tables.

(Source: http://lua-users.org/wiki/ForTutorial)

I'll try changing that in my fork and will submit a pull request if it works out.

elisee commented 11 years ago

I merged the latest changes. Any news on getting this into master? :)

mherkender commented 11 years ago

Sorry, totally forgot about this.

I've added your change, minus the parenthesis (not the style I've been using in this project). Thank you for your patience!

elisee commented 11 years ago

Thanks for merging!