public override bool Compare(TokenType type, ScriptObject obj) { ScorpioMethod method = m_UserdataType.GetComputeMethod(type); if (method == null) { throw new ExecutionException(m_Script, "找不到运算符重载 " + type); } return(true.Equals(method.Call(new ScriptObject[] { this, obj }))); }
public override ScriptObject Compute(Scorpio.Compiler.TokenType type, ScriptObject obj) { ScorpioMethod computeMethod = this.m_UserdataType.GetComputeMethod(type); if (computeMethod == null) { throw new ExecutionException(base.m_Script, "找不到运算符重载 " + type); } return(base.m_Script.CreateObject(computeMethod.Call(new ScriptObject[] { this, obj }))); }
/// <summary> 获得运算符重载的函数 </summary> public ScorpioMethod GetComputeMethod(TokenType type) { if (m_ComputeMethods.ContainsKey(type)) { return(m_ComputeMethods[type]); } else { ScorpioMethod method = GetComputeMethod_impl(type); m_ComputeMethods.Add(type, method); return(method); } }
public object Call(ScriptObject[] args) { Util.Assert(args.Length >= 2, m_script, "generic_method 参数必须大于等于2个"); ScriptFunction func = args[0] as ScriptFunction; Util.Assert(func != null, m_script, "generic_method 第1个参数必须是 function"); ScorpioMethod method = func.Method; Util.Assert(method != null, m_script, "generic_method 第1个参数必须是 程序函数"); ScriptObject[] pars = new ScriptObject[args.Length - 1]; Array.Copy(args, 1, pars, 0, pars.Length); return(method.MakeGenericMethod(pars)); }
public object Call(ScriptObject[] args) { ScriptMethodFunction func = args[0] as ScriptMethodFunction; Util.Assert(func != null, m_script, "generic_method 第1个参数必须是 function"); ScorpioMethod method = func.Method; Type[] types = new Type[args.Length - 1]; for (int i = 1; i < args.Length; ++i) { ScriptUserdata type = args[i] as ScriptUserdata; Util.Assert(type != null, m_script, "generic_method 第" + (i + 1) + "参数必须是 userdata"); types[i - 1] = type.ValueType; } return(method.MakeGenericMethod(types)); }
private Dictionary <string, ScriptFunction> m_Functions; //所有的函数 public DefaultScriptUserdataObject(Script script, object value) : base(script) { this.Value = value; this.ValueType = (Value is Type) ? (Type)Value : Value.GetType(); m_FieldInfos = new Dictionary <string, ScriptUserdataField>(); m_NestedTypes = new Dictionary <string, ScriptUserdata>(); m_Functions = new Dictionary <string, ScriptFunction>(); m_Constructor = new ScorpioMethod(ValueType.ToString(), ValueType.GetConstructors()); MethodInfo[] methods = ValueType.GetMethods(Script.BindingFlag); for (int i = 0; i < methods.Length; ++i) { string name = methods[i].Name; if (!m_Functions.ContainsKey(name)) { m_Functions.Add(name, Script.CreateFunction(new ScorpioMethod(ValueType, name, Value))); } } }
public object Call(ScriptObject[] args) { if (args.Length < 2) { throw new ExecutionException("generic_method 参数必须大于等于2个"); } ScriptFunction func = args[0] as ScriptFunction; if (func == null) { throw new ExecutionException("generic_method 参数必须是 function"); } ScorpioMethod method = func.Method; if (func == null) { throw new ExecutionException("generic_method 参数必须是 程序函数"); } ScriptObject[] pars = new ScriptObject[args.Length - 1]; Array.Copy(args, 1, pars, 0, pars.Length); return(method.MakeGenericMethod(pars)); }
public ScriptMethodFunction(Script script, String name, ScorpioMethod method) : base(script, name) { this.m_Method = method; }
} //返回程序函数对象 public ScriptMethodFunction(Script script, ScorpioMethod method) : this(script, method.MethodName, method) { }
public ScriptFunction CreateFunction(ScorpioMethod value) { return(new ScriptFunction(this, value)); }
public ScriptFunction(Script script, String strName, ScorpioMethod method) : base(script) { this.m_Method = method; Initialize(strName, FunstionType.Method); }