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

Cache issue Userdata.ExtensionType? #305

Open vin-spiegel opened 2 years ago

vin-spiegel commented 2 years ago

ExtensionType has cache issue?

public static class ExtMethods
{
  public static void Test1(this MyClass c) { Debug.Log("test1"); }
  public static void Test2(this MyClass c) { Debug.Log("test2"); }
  public static void Test3(this MyClass c) { Debug.Log("test3"); }
}

public class MyClass
{
  public MyClass() { }
}

public class Scripts
{
  Script _script = new Script();
  string _myScript = 
    "local a = Class()" + 
    "a.Test1()" + 
    "a.Test2()" + 
    "a.Test3()" + 
  public void InitScript()
  {
    UserData.RegisterExtensionType(typeof(ExtMethods));
    UserData.RegisterType(typeof(MyClass));
    _script.Globals["Class"] = typeof(MyClass)

    _script.DoString(_myScript);
  }
}

it only cache just first method of ExtensionType

local a = Class()
a.Test1() -- cache success
a.Test2() -- failed
a.Test3() -- failed