public override object[] Call(params object[] args) { Types types = new Types(); if (args != null) { for (int i = 0; i < args.Length; ++i) { var type = args[i].UnwrapDynamic() as Type; if (type == null) { return(null); } types.Add(type); } } var core = _Core.BindTypes(types); if (core != null) { var rv = ObjectPool.GetReturnValueFromPool(1); rv[0] = ClrCallable.GetFromPool(core, Target); return(rv); } return(null); }
public override object[] Call(params object[] args) { Types types = new Types(); if (args != null) { for (int i = 0; i < args.Length; ++i) { types.Add(args[i].UnwrapDynamic() as Type); if (types[i] == null) { return(null); } } } UniqueCallableCore ucore = _Core.FindAppropriate(types); if (ucore == null) { if (GLog.IsLogInfoEnabled) { GLog.LogInfo("Cann't find method with appropriate params."); } return(null); } else { var rv = ObjectPool.GetReturnValueFromPool(1); rv[0] = ClrCallable.GetFromPool(ucore, Target); return(rv); } }
public override object[] Call(object target, params object[] args) { if (args == null || args.Length <= 0) { if (GLog.IsLogInfoEnabled) { GLog.LogInfo("Unable to determine types of the generic method from the calling args - empty args."); } } else { if (args.Length == _GenericParams.Count) { Types types = new Types(); bool allTypes = true; foreach (var arg in args) { if (!(arg is Type)) { allTypes = false; break; } } if (allTypes) { for (int i = 0; i < args.Length; ++i) { types.Add(args[i] as Type); } ICallableCore core = BindTypes(types); if (core != null) { var rv = ObjectPool.GetReturnValueFromPool(1); rv[0] = ClrCallable.GetFromPool(core, target); return(rv); } } } // try to determine generic type params. var cored = this.DetermineGenericTypeArg(args); if (cored != null) { return(cored.Call(target, args)); } else { if (GLog.IsLogInfoEnabled) { GLog.LogInfo("Unable to determine types of the generic method from the calling args."); } } } return(null); }
public override object[] Call(params object[] args) { if (BindingCore != null) { var callable = ClrCallable.GetFromPool(BindingCore, null); var rv = callable.Call(args); callable.ReturnToPool(); return(rv); } return(null); }
public override object[] Call(params object[] args) { if (args != null && args.Length > 0) { var target = args[0].UnwrapDynamic(); var rv = ObjectPool.GetReturnValueFromPool(1); rv[0] = ClrCallable.GetFromPool(_Core, target); return(rv); } return(null); }
public static ClrCallable WrapDelegate(this Delegate del) { if (del != null) { #if NETFX_CORE var core = new UniqueCallableCore(del.GetType().GetMethod("Invoke")); var rv = ClrCallable.GetFromPool(core, del); #else var core = new UniqueCallableCore(del.GetDelegateMethod()); var rv = ClrCallable.GetFromPool(core, del.Target); #endif rv.Binding = del; return(rv); } return(null); }
public object[] Call(object target, params object[] args) { if (_GenericCore != null && args != null) { Types types = new Types(); bool allTypes = true; foreach (var arg in args) { if (!(arg is Type)) { allTypes = false; break; } } if (allTypes) { for (int i = 0; i < args.Length; ++i) { types.Add(args[i] as Type); } ICallableCore core = BindTypes(types); if (core != null) { var rv = ObjectPool.GetReturnValueFromPool(1); rv[0] = ClrCallable.GetFromPool(core, target); return(rv); } } } if (_NormalCore != null) { var rv = _NormalCore.Call(target, args); if (rv != null) { return(rv); } } if (_GenericCore != null) { return(_GenericCore.Call(target, args)); } return(null); }
public override object[] Call(params object[] args) { Types types = new Types(); if (args != null) { for (int i = 0; i < args.Length; ++i) { types.Add(args[i].UnwrapDynamic() as Type); } } if (types.Equals(_Core._MethodParamTypes)) { var rv = ObjectPool.GetReturnValueFromPool(1); rv[0] = ClrCallable.GetFromPool(_Core, Target); return(rv); } return(null); }
protected internal override object GetFieldImp(object key) { if (BindingCore != null) { string strkey = key.UnwrapDynamic <string>(); if ("___ol" == strkey) { return(BindingCore.CreateOverloadSelector(null)); } else if ("___ctor" == strkey) { return(ClrCallable.GetFromPool(BindingCore, null)); } var rv = BindingCore.GetFieldFor(null, key); if (rv != null) { return(rv); } } return(TypeObjectWrapper.GetFieldImp(key)); }
public override object[] Call(params object[] args) { Types types = new Types(); bool allTypes = true; if (args != null) { for (int i = 0; i < args.Length; ++i) { var type = args[i].UnwrapDynamic() as Type; if (type == null) { allTypes = false; break; } types.Add(type); } } if (allTypes) { var core = _Core.BindTypes(types); if (core != null) { var rv = ObjectPool.GetReturnValueFromPool(1); rv[0] = ClrCallable.GetFromPool(core, Target); return(rv); } } if (_Core._NormalCore != null) { return(_Core._NormalCore.CreateOverloadSelector(Target).Call(args)); } else { return(null); } }
public bool SetFieldFor(object tar, object key, object val) { if (_BindingType == null) { return(false); } tar = tar.UnwrapDynamic(); key = key.UnwrapDynamic(); var rval = val.UnwrapDynamic(); var fields = _ExpandedFields; if (tar == null) { fields = _StaticFields; } object finfo = null; if (key is string) { finfo = GetFieldDescFor(tar, key as string); if (finfo is PropertyInfo) { var pmethod = ((PropertyInfo)finfo).GetSetMethod(); if (pmethod != null) { try { Type type = ((PropertyInfo)finfo).PropertyType; if (type.IsSubclassOf(typeof(Delegate)) && rval is BaseDynamic) { rval = Capstones.LuaWrap.CapsLuaDelegateGenerator.CreateDelegate(type, rval as BaseDynamic); } if (rval.CanConvertRawObj(type)) { //((PropertyInfo)finfo).SetValue(tar, rval.ConvertType(type), null); var args = ObjectPool.GetParamsFromPool(1); args[0] = rval.ConvertType(type); pmethod.Invoke(tar, args); ObjectPool.ReturnParamsToPool(args); return(true); } } catch (Exception e) { // TODO: the debug info will decrease the performance. we should develop a generic lua-call-clr log. // perhaps we should make a Call and a TryCall. perhaps we should show which lua-state is doing the log. perhaps we should show lua-stack if (GLog.IsLogInfoEnabled) { GLog.LogInfo("Unable to set property: " + key + '\n' + e.ToString()); } throw; } } else { return(true); } } else if (finfo is FieldInfo) { Type type = ((FieldInfo)finfo).FieldType; if (type.IsSubclassOf(typeof(Delegate)) && rval is BaseDynamic) { rval = Capstones.LuaWrap.CapsLuaDelegateGenerator.CreateDelegate(type, rval as BaseDynamic); } if (rval.CanConvertRawObj(type)) { try { ((FieldInfo)finfo).SetValue(tar, rval.ConvertType(type)); return(true); } catch { if (GLog.IsLogInfoEnabled) { GLog.LogInfo("Unable to set field: " + key); } throw; } } return(true); } //else if (finfo is ICallableCore) //{ // // can't set a method; // return true; //} else if (finfo is EventInfo) { // we should only use +/- on EventInfo return(true); } } if (finfo == null) { object indexmethod = null; if (fields.TryGetValue("set_Item", out indexmethod)) { if (indexmethod is ICallableCore) { var callable = ClrCallable.GetFromPool((ICallableCore)indexmethod, tar); var rv = callable.Call(key, rval); callable.ReturnToPool(); if (rv != null) { return(true); } return(false); } } else if (tar is IList) { // special treat to array. var ikey = key.ConvertType(typeof(int)); if (ikey != null) { try { var cval = rval; if (tar.GetType().HasElementType) { cval = rval.ConvertType(tar.GetType().GetElementType()); } ((IList)tar)[(int)ikey] = cval; return(true); } catch { } } } } return(false); }
public object GetFieldFor(object tar, object key) { if (_BindingType == null) { return(null); } tar = tar.UnwrapDynamic(); key = key.UnwrapDynamic(); var fields = _ExpandedFields; if (tar == null) { fields = _StaticFields; } object finfo = null; if (key is string) { finfo = GetFieldDescFor(tar, key as string); if (finfo is PropertyInfo) { var pmethod = ((PropertyInfo)finfo).GetGetMethod(); if (pmethod != null) { try { //return ((PropertyInfo)finfo).GetValue(tar, null).WrapDynamic(); var args = ObjectPool.GetParamsFromPool(0); var rv = pmethod.Invoke(tar, args); ObjectPool.ReturnParamsToPool(args); return(rv); } catch { if (GLog.IsLogErrorEnabled) { GLog.LogError("Unable to get property: " + key); } throw; } } else { return(null); } } else if (finfo is FieldInfo) { return(((FieldInfo)finfo).GetValue(tar)); } else if (finfo is ICallableCore) { var core = finfo as ICallableCore; var callable = ClrCallable.GetFromPool(core, tar); return(callable); } else if (finfo is EventInfo) { return(ClrEventWrapper.GetFromPool(finfo as EventInfo, tar)); } } if (finfo == null) { object indexmethod = null; if (fields.TryGetValue("get_Item", out indexmethod)) { if (indexmethod is ICallableCore) { var callable = ClrCallable.GetFromPool((ICallableCore)indexmethod, tar); var rv = callable.Call(key); callable.ReturnToPool(); if (rv != null && rv.Length > 0) { return(rv[0]); } } } else if (tar is IList) { // special treat to array. var ikey = key.ConvertType(typeof(int)); if (ikey != null) { try { var rv = ((IList)tar)[(int)ikey]; return(rv); } catch { } } } } return(finfo); }