使用的地方
//UnityEngineComponentWrap.cs [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int _g_get_transform(RealStatePtr L) { try { #if L_LUA_PROFILER UnityEngine.Profiling.Profiler.BeginSample("[c#]UnityEngine.Component:get_transform"); #endif ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); UnityEngine.Component gen_to_be_invoked = (UnityEngine.Component)translator.FastGetCSObj(L, 1); translator.Push(L, gen_to_be_invoked.transform); } catch(System.Exception gen_e) { #if L_LUA_PROFILER UnityEngine.Profiling.Profiler.EndSample(); #endif return LuaAPI.luaL_error(L, "c# exception:" + gen_e); } #if L_LUA_PROFILER UnityEngine.Profiling.Profiler.EndSample(); #endif return 1; } --lua调用 obj.transform
当lua层调用gameobject中的.tranform时,会调用到wrap里面的getter, 两个关键的地方translator.FastGetCSObj(L, 1);和translator.Push(L, gen_to_be_invoked.transform); 前者是从lua栈中得到传过来的gameobject,后者是将gameobject身上的transform压入lua栈。