Browse Source

Merge pull request #189 from dorisugita/patch-2

Support unboxing nil Lua values to CLR (default) value types.
Benjamin Dobell 6 years ago
parent
commit
e9c102243d
1 changed files with 6 additions and 1 deletions
  1. 6 1
      src/MoonSharp.Interpreter/DataTypes/DynValue.cs

+ 6 - 1
src/MoonSharp.Interpreter/DataTypes/DynValue.cs

@@ -874,7 +874,12 @@ namespace MoonSharp.Interpreter
 		/// </summary>
 		/// </summary>
 		public T ToObject<T>()
 		public T ToObject<T>()
 		{
 		{
-			return (T)ToObject(typeof(T));
+			T myObject = (T)ToObject(typeof(T));
+			if (myObject == null) {
+				return default(T);
+			}
+			
+			return myObject;
 		}
 		}
 
 
 #if HASDYNAMIC
 #if HASDYNAMIC