Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C#函数,使用in/ref/out修饰的参数,如果再支持默认值,则xlua会报错 #1105

Open
ajycode opened this issue Dec 15, 2023 · 0 comments

Comments

@ajycode
Copy link

ajycode commented Dec 15, 2023

见OverloadMethodWrap类的Init方法
var defalutValue = paramInfos[i].DefaultValue; if (paramInfos[i].IsOptional) { if (defalutValue != null && defalutValue.GetType() != paramInfos[i].ParameterType) { defalutValue = defalutValue.GetType() == typeof(Missing) ? (paramInfos[i].ParameterType.IsValueType() ? Activator.CreateInstance(paramInfos[i].ParameterType) : Missing.Value) : Convert.ChangeType(defalutValue, paramInfos[i].ParameterType); } HasDefalutValue = true; }

如果函数参数支持默认值,则会进入到这段代码,会根据参数类型对默认值做强制转换
但是如果函数参数是被in/out/ref修饰的,假设参数类型是T,则函数参数的实际类型是T&,而默认值参数类型是T,这里做强制转换被失败抛出异常,导致类的后续函数不会被收集。

这里应该再需要加上一条判断语句
defalutValue.GetType().MakeByRefType() != paramInfos[i].ParameterType

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant