xLua icon indicating copy to clipboard operation
xLua copied to clipboard

Problem with delegate Int parameter

Open tamv-ika opened this issue 4 years ago • 9 comments

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.

tamv-ika avatar Jun 10 '21 14:06 tamv-ika

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

chexiongsheng avatar Jun 11 '21 00:06 chexiongsheng

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

tamv-ika avatar Jun 11 '21 01:06 tamv-ika

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

chexiongsheng avatar Jun 11 '21 01:06 chexiongsheng

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

tamv-ika avatar Jun 11 '21 01:06 tamv-ika

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?

chexiongsheng avatar Jun 11 '21 09:06 chexiongsheng

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?

tamv-ika avatar Jun 11 '21 09:06 tamv-ika

you mush clear generate code after you change the configure.

chexiongsheng avatar Jun 11 '21 11:06 chexiongsheng

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

tamv-ika avatar Jun 11 '21 12:06 tamv-ika