MCPcopy Create free account
hub / github.com/Tencent/xLua / CreateDelegateBridge

Method CreateDelegateBridge

Assets/XLua/Src/ObjectTranslator.cs:462–531  ·  view source on GitHub ↗
(RealStatePtr L, Type delegateType, int idx)

Source from the content-addressed store, hash-verified

460 }
461 Dictionary<int, WeakReference> delegate_bridges = new Dictionary<int, WeakReference>();
462 public object CreateDelegateBridge(RealStatePtr L, Type delegateType, int idx)
463 {
464 LuaAPI.lua_pushvalue(L, idx);
465 LuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);
466 if (!LuaAPI.lua_isnil(L, -1))
467 {
468 int referenced = LuaAPI.xlua_tointeger(L, -1);
469 LuaAPI.lua_pop(L, 1);
470
471 if (delegate_bridges[referenced].IsAlive)
472 {
473 if (delegateType == null)
474 {
475 return delegate_bridges[referenced].Target;
476 }
477 DelegateBridgeBase exist_bridge = delegate_bridges[referenced].Target as DelegateBridgeBase;
478 Delegate exist_delegate;
479 if (exist_bridge.TryGetDelegate(delegateType, out exist_delegate))
480 {
481 return exist_delegate;
482 }
483 else
484 {
485 exist_delegate = getDelegate(exist_bridge, delegateType);
486 exist_bridge.AddDelegate(delegateType, exist_delegate);
487 return exist_delegate;
488 }
489 }
490 }
491 else
492 {
493 LuaAPI.lua_pop(L, 1);
494 }
495
496 LuaAPI.lua_pushvalue(L, idx);
497 int reference = LuaAPI.luaL_ref(L);
498 LuaAPI.lua_pushvalue(L, idx);
499 LuaAPI.lua_pushnumber(L, reference);
500 LuaAPI.lua_rawset(L, LuaIndexes.LUA_REGISTRYINDEX);
501 DelegateBridgeBase bridge;
502 try
503 {
504 bridge = Activator.CreateInstance(delegate_birdge_type, new object[] { reference, luaEnv }) as DelegateBridgeBase;
505 }
506 catch(Exception e)
507 {
508 LuaAPI.lua_pushvalue(L, idx);
509 LuaAPI.lua_pushnil(L);
510 LuaAPI.lua_rawset(L, LuaIndexes.LUA_REGISTRYINDEX);
511 LuaAPI.lua_pushnil(L);
512 LuaAPI.xlua_rawseti(L, LuaIndexes.LUA_REGISTRYINDEX, reference);
513 throw e;
514 }
515 if (delegateType == null)
516 {
517 delegate_bridges[reference] = new WeakReference(bridge);
518 return bridge;
519 }

Callers 2

GetEventWrapMethod · 0.80
genCasterMethod · 0.80

Calls 13

lua_pushvalueMethod · 0.80
lua_rawgetMethod · 0.80
lua_isnilMethod · 0.80
xlua_tointegerMethod · 0.80
lua_popMethod · 0.80
TryGetDelegateMethod · 0.80
AddDelegateMethod · 0.80
luaL_refMethod · 0.80
lua_pushnumberMethod · 0.80
lua_rawsetMethod · 0.80
lua_pushnilMethod · 0.80
xlua_rawsetiMethod · 0.80

Tested by

no test coverage detected