From 332d66cac90c6d75a8f67670203a2b233f796359 Mon Sep 17 00:00:00 2001 From: bplu4t2f Date: Sun, 29 Jan 2017 18:01:54 +0100 Subject: [PATCH 1/2] Passing null as value parameter in Table.Set now removes the table entry instead of causing a NullReferenceException in Table.PerformTableSet --- src/MoonSharp.Interpreter/DataTypes/Table.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/MoonSharp.Interpreter/DataTypes/Table.cs b/src/MoonSharp.Interpreter/DataTypes/Table.cs index c4a4bec4..ea4299f5 100644 --- a/src/MoonSharp.Interpreter/DataTypes/Table.cs +++ b/src/MoonSharp.Interpreter/DataTypes/Table.cs @@ -161,6 +161,12 @@ public void Append(DynValue value) private void PerformTableSet(LinkedListIndex listIndex, T key, DynValue keyDynValue, DynValue value, bool isNumber, int appendKey) { + if (value == null) + { + PerformTableRemove(listIndex, key, isNumber); + return; + } + TablePair prev = listIndex.Set(key, new TablePair(keyDynValue, value)); // If this is an insert, we can invalidate all iterators and collect dead keys From 9c753896fb84f0f9d1cfd2a917bac8ee37f437ca Mon Sep 17 00:00:00 2001 From: bplu4t2f Date: Sat, 4 Feb 2017 12:55:05 +0100 Subject: [PATCH 2/2] Copied changes to .netcore project --- .../MoonSharp.Interpreter.netcore/src/DataTypes/Table.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/MoonSharp.Interpreter/_Projects/MoonSharp.Interpreter.netcore/src/DataTypes/Table.cs b/src/MoonSharp.Interpreter/_Projects/MoonSharp.Interpreter.netcore/src/DataTypes/Table.cs index c4a4bec4..ea4299f5 100644 --- a/src/MoonSharp.Interpreter/_Projects/MoonSharp.Interpreter.netcore/src/DataTypes/Table.cs +++ b/src/MoonSharp.Interpreter/_Projects/MoonSharp.Interpreter.netcore/src/DataTypes/Table.cs @@ -161,6 +161,12 @@ public void Append(DynValue value) private void PerformTableSet(LinkedListIndex listIndex, T key, DynValue keyDynValue, DynValue value, bool isNumber, int appendKey) { + if (value == null) + { + PerformTableRemove(listIndex, key, isNumber); + return; + } + TablePair prev = listIndex.Set(key, new TablePair(keyDynValue, value)); // If this is an insert, we can invalidate all iterators and collect dead keys