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.41k stars 213 forks source link

CLR types don't get converted correctly when allowing auto-registration of userdata #274

Open redxdev opened 4 years ago

redxdev commented 4 years ago

When using automatic registration of types, the table from here isn't true for the more complex types (type/methodinfo/list/dictionary/enumerable/etc) due to ClrToScriptConversions.ObjectToDynValue using UserData.Create to check if the value is valid userdata.

The problem is that UserData.Create will (almost?) always end up auto-registering whatever type you pass and never hit the block that creates the table/dictionary/method/etc.

The fix is probably to check whether the passed object is of a registered type first: