moonsharp-devs / moonsharp

An interpreter for the Lua language, written entirely in C# for the .NET, Mono, Xamarin and Unity3D platforms, including handy remote debugger facilities.
http://www.moonsharp.org
Other
1.42k stars 214 forks source link

Assigning nil to a table field should delete it #41

Closed willjouo closed 9 years ago

willjouo commented 9 years ago

In Lua 5.2, this code:

function showTable(t)
    for i, j in pairs(t) do
        print(j)
    end
end

tb = {}
tb["id"] = 3

print("Before:")
showTable(tb)

tb["id"] = nil

print("After:")
showTable(tb)
print("End")

outputs this:

Before:
3
After:
End

while in Moonsharp it outputs:

Before:
3
After:
nil
End

In my script I want to add and remove a lot of values in a table so I always end up with a huge table filled with nil values, which is useless. table.remove(tbl, pos) don't work because pos must be an integer of the position, and can't be a string for the key like here with the associative array.

xanathar commented 9 years ago

Fixed on master branch.