Unity3D + ulua simpleframework的问题汇总

本文讨论了在使用最新版本的ulua时,生成wrapper文件时对范型支持存在的问题,具体为生成错误的类型导致编译失败。通过代码审查发现原因,并提出了修正方案,确保了类型正确转换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用最新版本的(此时最新)的ulua, 生成wrapper文件时,对范型支持支持不是很好,如:

{System.Collections.Generic.List`1[System.String]&} 的type类型,会生成出System.Collections.Generic.List`1[System.String]到c#中,导致编译不通过。

经过代码review, 发现ToLuaExport文件中的GetStrType,对上面的类型判断IsGenericType返回false, 不确定是否是什么原因(&)引起的, 

所以在else中修改成如下代码,就可以生成List<String>

else if(t.IsGenericType)
        {
            return GetGenericName(t);
        }
        else
        {
			// modified by cpeng for il2cpp
			// referenced to BindLua::GetGenericName
<span style="font-family: Menlo;">				Debug.Log("IsGenericType not work for " + t.ToString());</span>
			// t.IsGenericType for {System.Collections.Generic.List`1[System.String]&} somehow return false, we handle it here.
			if (t.GetGenericArguments().Length != 0) {
				Type[] gArgs = t.GetGenericArguments();
				string typeName = t.Name;
				string pureTypeName = typeName.Substring(0, typeName.IndexOf('`'));
				
				return pureTypeName + "<" + string.Join(",", GetGenericName(gArgs)) + ">";
			}
			return _C(t.ToString());            
        }




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值