__index __newindex metamethod

本文介绍如何使用Lua的元表机制实现对象属性的默认值及保护。通过定义__index和__newindex metamethods,可以控制表中不存在字段的访问与赋值行为。

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

 

: ReportException: LuaException: c# exception:System.NullReferenceException: Object reference not set to an instance of an object. c# exception:System.NullReferenceException: Object reference not set to an instance of an object. at XLua.CSObjectWrap.SpineUnitySkeletonGraphicWrap._s_set_skeletonDataAsset (System.IntPtr L) [0x00000] in <00000000000000000000000000000000>:0 at XLua.DelegateBridge.__Gen_Delegate_Imp35 (COL.UnityGameWheels.Core.Asset.IAssetAccessor p0, System.Object p1) [0x00000] in <00000000000000000000000000000000>:0 at COL.UnityGameWheels.Core.Asset.OnLoadAssetSuccess.Invoke (COL.UnityGameWheels.Core.Asset.IAssetAccessor assetAccessor, System.Object context) [0x00000] in <00000000000000000000000000000000>:0 at COL.UnityGameWheels.Core.Asset.AssetModule+Loader+AssetCache.CallLoadAssetSuccess (COL.UnityGameWheels.Core.Asset.AssetAccessor assetAccessor) [0x00000] in <00000000000000000000000000000000>:0 at COL.UnityGameWheels.Core.Asset.AssetModule+Loader+AssetCache.SucceedAndNotify () [0x00000] in <00000000000000000000000000000000>:0 at System.Action`1[T].Invoke (T obj) [0x00000] in <00000000000000000000000000000000>:0 at COL.UnityGameWheels.Core.Asset.AssetModule+Loader.UpdateTickDelegates (COL.UnityGameWheels.Core.TimeStruct timeStruct) [0x00000] in <00000000000000000000000000000000>:0 at COL.UnityGameWheels.Core.Asset.AssetModule+Loader.Update (COL.UnityGameWheels.Core.TimeStruct timeStruct) [0x00000] in <00000000000000000000000000000000>:0 stack traceback: [C]: in ? [C]: in metamethod '__newindex' Common/AnimatorUtil.lua:843: in upvalue 'onSuccess' AssetExtensionLua.lua:74: in function <AssetExtensionLua.lua:72> ********* XLua.LuaEnv.ThrowExceptionFromError (System.Int32 oldTop) (at <00000000000000000000000000000000>.0) XLua.DelegateBridge.__Gen_Delegate_Imp35 (COL.UnityGameWheels.Core.Asset.IAssetAccessor p0, System.Object p1) (at <00000000000000000000000000000000>.0) COL.UnityGameWheels.Core.Asset.OnLoadAssetSuccess.Invoke (COL.UnityGameWheels.Core.
最新发布
04-01
lua报错nil nil error! c# exception:XLua.LuaException: c# exception:UnityEngine.MissingComponentException: There is no 'MeshRenderer' attached to the "ch_architect" game object, but a script is trying to access it. You probably need to add a MeshRenderer to the game object "ch_architect". Or your script needs to check if the component is attached before using it. at (wrapper managed-to-native) UnityEngine.Renderer.set_sortingLayerName(UnityEngine.Renderer,string) at XLua.CSObjectWrap.UnityEngineRendererWrap._s_set_sortingLayerName (System.IntPtr L) [0x0001c] in D:\DreamLandProjects\DreamLandc301\Assets\XLua\Gen\UnityEngine_RendererWrap.cs:1040 stack traceback: [C]: in ? [C]: in ? [C]: in metamethod '__newindex' Common/UI/UIASpine:136: in function 'Common/UI/UIASpine.SetSort' UI/Hero/UITeamItems:299: in upvalue 'CB' Common/Unit/SingleChild:179: in upvalue 'CB' Common/Unit/SingleChild:102: in upvalue 'CB' Common/UI/UIItem:45: in upvalue 'CB' Common/Unit/Unit:100: in upvalue 'CB' Common/UI/UIASpine:26: in function <Common/UI/UIASpine:22> ... UI/Hero/UITeamItems:296: in field 'fReset' Common/UI/UIUnit:53: in function 'Common/UI/UIUnit.Reset' UI/Team/UITeamMain:326: in function 'UI/Team/UITeamMain.UpdateSlots' UI/Team/UITeamMain:311: in function 'UI/Team/UITeamMain.UpdateTeamBtns' UI/Team/UITeamMain:49: in function 'UI/Team/UITeamMain.OnEnter' [C]: in function 'xpcall' InitLib:63: in function 'xpcall_0' UI/Common/UIManager:141: in function 'UI/Common/UIManager.EnterPanel' UI/Common/UIManager:114: in function 'UI/Common/UIManager.OpenPanel' UI/Common/UIManager:189: in upvalue 'LoadedCB' UI/Common/UIManager:610: in function <UI/Common/UIManager:574>
06-13
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值