Tencent / xLua

xLua is a lua programming solution for C# ( Unity, .Net, Mono) , it supports android, ios, windows, linux, osx, etc.
Other
9.4k stars 2.46k forks source link

Problem with delegate Int parameter #898

Open tamv-ika opened 3 years ago

tamv-ika commented 3 years ago

Hi, I use xlua-2.1.16 build with luajit for win64, I got a problem with calling delegate from lua, I try to call a delegate with int parameter then it throws an exception "This type must add to CSharpCallLua: ...". But when I try the same thing with another delegate which pass a string as parameter, It worked as expected. Both are add to a list which has tag [CSharpCallLua]. This exception also rise when the parameter is an enum type.

chexiongsheng commented 3 years ago

Are you using xlua in unity? If so, delegate with valuetype must add to a list (static field) which has tag [CSharpCallLua]. If you are not using xlua in unity, winform for example, update to this version: https://github.com/Tencent/xLua/commit/2c1c80fe03f14cbcdfa3826485e31d40fc8f2d68

tamv-ika commented 3 years ago

I use Unity 2019.4 I also added to the list, with other type like string, double or other class it work fine but with int value it throw eception. I walk around by wrap it into a class then it works

chexiongsheng commented 3 years ago

example: https://github.com/Tencent/xLua/blob/master/Assets/XLua/Examples/ExampleGenConfig.cs#L57

tamv-ika commented 3 years ago

I did same as example, the weird thing is other type work fine but it failed with int param and enum :(

chexiongsheng commented 3 years ago

Delegate without valuetype parameter not required add to CSharpCallLua, that is why other type work fine. CSharpCallLua list configure is existing for years and not changed, it impossible not working. i think it is something wrong with your configure, show your configure?

tamv-ika commented 3 years ago

Here is my configure list [CSharpCallLua] public static List<Type> csharpCallLua = new List<Type>() { typeof(System.Net.Security.RemoteCertificateValidationCallback), typeof(Test.MyDelegateStr), typeof(Test.MyDelegateInt), typeof(Test.MyDelegateDouble), typeof(EventHandler), typeof(Action), typeof(Action<string>), typeof(Action<byte[]>), typeof(Action<int>), typeof(UnityEngine.Events.UnityAction), typeof(System.Collections.IEnumerator) };

the Action<int> is not working. I also tried with custom delegates Test.MyDelegateStr, Test.MyDelegateInt, Test.MyDelegateDouble which take one argument with the type string, int and double, then only string and double work, the delegate with int throws exception. Could you check it?

chexiongsheng commented 3 years ago

you mush clear generate code after you change the configure.

tamv-ika commented 3 years ago

Of course, I cleared and re-generated code but it’s still fail

JosephStar318 commented 1 month ago

Have you found a solution? For me its Func<bool> that causing issues. Even though it is added to CSharpCallLua and generated properly it gives error.