public override ScriptObject AssignCompute(TokenType type, ScriptObject obj) { if (type == TokenType.AssignPlus) { m_Value += obj.ToString(); return this; } throw new ExecutionException(m_Script, this, "String类型 操作符[" + type + "]不支持"); }
//初始化所有数据 每次调用 Execute 调用 private void Reset() { m_returnObject = null; m_Over = false; m_Break = false; m_Continue = false; }
public override ScriptObject Compute(TokenType type, ScriptObject value) { if (type != TokenType.Plus) { return base.Compute(type, value); } ScriptTable table = value as ScriptTable; if (table == null) throw new ExecutionException(m_Script, this, "table [+] 操作只限两个[table]之间,传入数据类型:" + value.Type); ScriptTable ret = m_Script.CreateTable(); ScriptObject obj = null; ScriptScriptFunction func = null; foreach (KeyValuePair<object, ScriptObject> pair in m_listObject) { obj = pair.Value.Clone(); if (obj is ScriptScriptFunction) { func = (ScriptScriptFunction)obj; if (!func.IsStaticFunction) func.SetTable(ret); } ret.m_listObject[pair.Key] = obj; } foreach (KeyValuePair<object, ScriptObject> pair in table.m_listObject) { obj = pair.Value.Clone(); if (obj is ScriptScriptFunction) { func = (ScriptScriptFunction)obj; if (!func.IsStaticFunction) func.SetTable(ret); } ret.m_listObject[pair.Key] = obj; } return ret; }
public object Call(ScriptObject[] args) { if (args == null || args.Length == 0) return null; string messagePattern = (args[0] as ScriptString).Value; if (args.Length == 1) return messagePattern; StringBuilder sbuf = new StringBuilder(); int L; if (args[1] is ScriptArray) { L = 0; args = ((ScriptArray)args[1]).ToArray(); } else { L = 1; } int length = args.Length; int i = 0, j = 0; for (; L < length; L++) { j = messagePattern.IndexOf(DELIM_STR, i); if (j == -1) { if (i == 0) { return messagePattern; } else { sbuf.Append(messagePattern.Substring(i)); return sbuf.ToString(); } } else { sbuf.Append(messagePattern.Substring(i, j - i)); sbuf.Append(args[L].ToString()); i = j + 2; } } sbuf.Append(messagePattern.Substring(i)); return sbuf.ToString(); }
public object call(params object[] args) { int length = args.Length; ScriptObject[] parameters = new ScriptObject[length]; for (int i = 0; i < length; ++i) parameters[i] = m_Script.CreateObject(args[i]); return Call(parameters); }
public override object Call(ScriptObject[] parameters) { try { return m_Handle.Call(parameters); } catch (System.Exception ex) { throw new ExecutionException(m_Script, "CallFunction [" + Name + "] is error : " + ex.ToString()); } }
public object Call(ScriptObject[] args) { string messagePattern = (args[0] as ScriptString).Value; if (args.Length == 1) return messagePattern; if (args.Length == 3) return messagePattern.Substring((args[1] as ScriptNumber).ToInt32(), (args[2] as ScriptNumber).ToInt32()); else return messagePattern.Substring((args[1] as ScriptNumber).ToInt32()); }
/// <summary> 设置一个类变量 </summary> public void SetValue(object obj, string name, ScriptObject value) { UserdataField field = GetField(name); if (field == null) throw new ExecutionException(m_Script, "SetValue Type[" + m_Type + "] 变量 [" + name + "] 不存在"); try { field.SetValue(obj, Util.ChangeType(m_Script, value, field.FieldType)); } catch (System.Exception e) { throw new ExecutionException(m_Script, "不能从源类型:" + (value == null || value.IsNull ? "null" : value.ObjectValue.GetType().Name) + " 转换成目标类型:" + field.FieldType.Name + " : " + e.ToString()); } }
public static bool CanChangeType(ScriptObject[] pars, Type[] types) { if (pars.Length != types.Length) return false; for (int i = 0; i < pars.Length;++i ) { if (!CanChangeType(pars[i], types[i])) return false; } return true; }
public object Call(ScriptObject[] args) { if (m_Enumerator.MoveNext()) { ScriptTable table = m_Script.CreateTable(); table.SetValue("key", m_Script.CreateObject(m_Index++)); table.SetValue("value", m_Enumerator.Current); return table; } return null; }
public object Call(ScriptObject[] args) { if (m_Enumerator.MoveNext()) { ScriptTable table = m_Script.CreateTable(); KeyValuePair<object, ScriptObject> v = m_Enumerator.Current; table.SetValue("key", m_Script.CreateObject(v.Key)); table.SetValue("value", v.Value); return table; } return null; }
public object Call(ScriptObject[] args) { int num = args.Length; if (num == 0) return 0f; double num2 = (args[0] as ScriptNumber).ToDouble(); for (int i = 1; i < num; i++) { double num3 = (args[i] as ScriptNumber).ToDouble(); if (num3 > num2) num2 = num3; } return num2; }
private bool SetVariableObject(string name, ScriptObject obj) { if (m_variableDictionary.ContainsKey(name)) { m_variableDictionary[name] = obj.Assign(); return true; } if (m_parent != null) { return m_parent.SetVariableObject(name, obj); } return false; }
public object Call(String strName, params object[] args) { ScriptObject obj = m_GlobalTable.GetValue(strName); if (obj is ScriptNull) throw new ScriptException("找不到变量[" + strName + "]"); int length = args.Length; ScriptObject[] parameters = new ScriptObject[length]; for (int i = 0; i < length;++i ) { parameters[i] = CreateObject(args[i]); } m_StackInfoStack.Clear(); return obj.Call(parameters); }
public object Call(object obj, ScriptObject[] parameters) { if (m_Count == 0) throw new ExecutionException(m_Script, "找不到函数 [" + MethodName + "]"); FunctionMethod methodInfo = null; if (m_Count == 1) { methodInfo = m_Methods[0]; if (!methodInfo.IsValid) throw new ExecutionException(m_Script, "Type[" + m_Type.ToString() + "] 找不到合适的函数 [" + MethodName + "]"); } else { foreach (FunctionMethod method in m_Methods) { if (method.IsValid && Util.CanChangeType(parameters, method.ParameterType)) { methodInfo = method; break; } } } try { if (methodInfo != null && !methodInfo.Params) { int length = methodInfo.ParameterType.Length; object[] objs = methodInfo.Args; for (int i = 0; i < length; i++) objs[i] = Util.ChangeType(m_Script, parameters[i], methodInfo.ParameterType[i]); return methodInfo.Invoke(obj, m_Type); } else { foreach (FunctionMethod method in m_Methods) { int length = method.ParameterType.Length; if (method.Params && parameters.Length >= length - 1) { bool fit = true; for (int i = 0; i < parameters.Length; ++i) { if (!Util.CanChangeType(parameters[i], i >= length - 1 ? method.ParamType : method.ParameterType[i])) { fit = false; break; } } if (fit) { object[] objs = method.Args; for (int i = 0; i < length - 1; ++i) objs[i] = Util.ChangeType(m_Script, parameters[i], method.ParameterType[i]); Array array = Array.CreateInstance(method.ParamType, parameters.Length - length + 1); for (int i = length - 1; i < parameters.Length; ++i) array.SetValue(Util.ChangeType(m_Script, parameters[i], method.ParamType), i - length + 1); objs[length - 1] = array; return method.Invoke(obj, m_Type); } } } } } catch (System.Exception e) { throw new ExecutionException(m_Script, "Type[" + m_Type.ToString() + "] 调用函数出错 [" + MethodName + "] : " + e.ToString()); } throw new ExecutionException(m_Script, "Type[" + m_Type.ToString() + "] 找不到合适的函数 [" + MethodName + "]"); }
public override object Call(ScriptObject[] parameters) { int length = parameters.Length; Util.Assert(length > 0, m_script, "length > 0"); if (length > 1) { ScriptObject[] pars = new ScriptObject[parameters.Length - 1]; Array.Copy(parameters, 1, pars, 0, pars.Length); if (parameters[0] is ScriptNumber) return m_Method.Call(Util.ChangeType_impl(parameters[0].ObjectValue, m_Type), pars); else return m_Method.Call(parameters[0].ObjectValue, pars); } else { return m_Method.Call(parameters[0].ObjectValue, new ScriptObject[0]); } }
public override bool Compare(TokenType type, ScriptObject obj) { ScriptString val = obj as ScriptString; if (val == null) throw new ExecutionException(m_Script, this, "字符串比较 右边必须为字符串类型"); switch (type) { case TokenType.Greater: return string.Compare(m_Value, val.m_Value) > 0; case TokenType.GreaterOrEqual: return string.Compare(m_Value, val.m_Value) >= 0; case TokenType.Less: return string.Compare(m_Value, val.m_Value) < 0; case TokenType.LessOrEqual: return string.Compare(m_Value, val.m_Value) <= 0; default: throw new ExecutionException(m_Script, this, "String类型 操作符[" + type + "]不支持"); } }
public override bool Compare(TokenType type, ScriptObject obj) { ScriptNumberDouble val = obj as ScriptNumberDouble; if (val == null) throw new ExecutionException(m_Script, this, "数字比较 两边的数字类型不一致 请先转换再比较"); switch (type) { case TokenType.Greater: return m_Value > val.m_Value; case TokenType.GreaterOrEqual: return m_Value >= val.m_Value; case TokenType.Less: return m_Value < val.m_Value; case TokenType.LessOrEqual: return m_Value <= val.m_Value; default: throw new ExecutionException(m_Script, this, "Double类型 操作符[" + type + "]不支持"); } }
public static object ChangeType(Script script, ScriptObject par, Type type) { if (type == TYPE_OBJECT) { return par.ObjectValue; } else { if (par is ScriptUserdata && type == TYPE_TYPE) return ((ScriptUserdata)par).ValueType; else if (par is ScriptNumber) return ChangeType_impl(par.ObjectValue, type); else if (TYPE_DELEGATE.GetTypeInfo().IsAssignableFrom(type)) { if (par is ScriptFunction) return script.GetDelegate(type).Call(new ScriptObject[] { par }); else return par.ObjectValue; } else return par.ObjectValue; } }
public static object ChangeType(Script script, ScriptObject par, Type type) { if (type == TYPE_OBJECT) { return par.ObjectValue; } else { if (par is ScriptUserdata && Util.IsType(type)) return ((ScriptUserdata)par).ValueType; else if (par is ScriptNumber) return ChangeType_impl(par.ObjectValue, type); else if (Util.IsDelegateType(type)) { if (par is ScriptFunction) return script.GetUserdataFactory().GetDelegate(type).Call(new ScriptObject[] { par }); else return par.ObjectValue; } else return par.ObjectValue; } }
public override ScriptObject Compute(TokenType type, ScriptObject obj) { ScriptNumber val = obj as ScriptNumber; if (val == null) throw new ExecutionException(m_Script, this, "逻辑计算 右边值必须为数字类型"); switch (type) { case TokenType.Plus: return new ScriptNumberDouble(m_Script, m_Value + val.ToDouble()); case TokenType.Minus: return new ScriptNumberDouble(m_Script, m_Value - val.ToDouble()); case TokenType.Multiply: return new ScriptNumberDouble(m_Script, m_Value * val.ToDouble()); case TokenType.Divide: return new ScriptNumberDouble(m_Script, m_Value / val.ToDouble()); case TokenType.Modulo: return new ScriptNumberDouble(m_Script, m_Value % val.ToDouble()); default: throw new ExecutionException(m_Script, this, "Double不支持的运算符 " + type); } }
public ScriptObject Call(ScriptContext parentContext, Dictionary<String, ScriptObject> objs, ScriptObject[] parameters) { int length = parameters.Length; if (m_Params) { ScriptArray paramsArray = m_Script.CreateArray(); for (int i = 0; i < m_ParameterCount - 1; ++i) { objs[m_ListParameters[i]] = (parameters != null && length > i) ? parameters[i] : m_Script.Null; } for (int i = m_ParameterCount - 1; i < length; ++i) { paramsArray.Add(parameters[i]); } objs[m_ListParameters[m_ParameterCount - 1]] = paramsArray; } else { for (int i = 0; i < m_ParameterCount; ++i) { objs[m_ListParameters[i]] = (parameters != null && length > i) ? parameters[i] : m_Script.Null; } } ScriptContext context = new ScriptContext(m_Script, m_ScriptExecutable, parentContext, Executable_Block.Function); context.Initialize(objs); return context.Execute(); }
public ScriptObject Call(Dictionary<String, ScriptObject> objs, ScriptObject[] parameters) { int length = parameters.Length; if (m_Params) { m_ParamsArray.Clear(); for (int i = 0; i < m_ParameterCount - 1; ++i) { objs[m_ListParameters[i]] = (parameters != null && length > i) ? parameters[i] : m_Script.Null; } for (int i = m_ParameterCount - 1; i < length; ++i) { m_ParamsArray.Add(parameters[i]); } objs[m_ListParameters[m_ParameterCount - 1]] = m_ParamsArray; } else { for (int i = 0; i < m_ParameterCount; ++i) { objs[m_ListParameters[i]] = (parameters != null && length > i) ? parameters[i] : m_Script.Null; } } m_Context.Initialize(m_ParentContext, objs); return m_Context.Execute(); }
public static bool CanChangeType(ScriptObject par, Type type) { if (type == TYPE_OBJECT) return true; else if (IsNumber(type)) return par is ScriptNumber; else if (IsBool(type)) return par is ScriptBoolean; else if (IsEnum(type)) return par is ScriptEnum && ((ScriptEnum)par).EnumType == type; else if (par is ScriptNull) return true; else if (IsString(type)) return par is ScriptString; else if (IsDelegateType(type)) return (par is ScriptFunction) || (par is ScriptUserdata && (par as ScriptUserdata).ValueType == type); else if (IsType(type)) return par is ScriptUserdata; else if (par is ScriptUserdata) return type.IsAssignableFrom(((ScriptUserdata)par).ValueType); else return type.IsAssignableFrom(par.GetType()); }
public static bool CanChangeType(ScriptObject par, Type type) { if (type == TYPE_OBJECT) return true; else if (type == TYPE_SBYTE || type == TYPE_BYTE || type == TYPE_SHORT || type == TYPE_USHORT || type == TYPE_INT || type == TYPE_UINT || type == TYPE_FLOAT || type == TYPE_DOUBLE || type == TYPE_DECIMAL || type == TYPE_LONG) return par is ScriptNumber; else if (type == TYPE_BOOL) return par is ScriptBoolean; else if (type.GetTypeInfo().IsEnum) return par is ScriptEnum && ((ScriptEnum)par).EnumType == type; else if (par is ScriptNull) return true; else if (type == TYPE_STRING) return par is ScriptString; else if (type == TYPE_TYPE) return par is ScriptUserdata; else if (TYPE_DELEGATE.GetTypeInfo().IsAssignableFrom(type)) return (par is ScriptFunction) || (par is ScriptUserdata && (par as ScriptUserdata).ValueType == type); else if (par is ScriptUserdata) return type.GetTypeInfo().IsAssignableFrom(((ScriptUserdata)par).ValueType); else return type.GetTypeInfo().IsAssignableFrom(par.GetType()); }
public object Call(ScriptObject[] args) { return ((ScriptTable)args [0]).GetValues (); }
public object Call(ScriptObject[] args) { return ((ScriptTable)args[0]).HasValue(args[1].ObjectValue); }
public object Call(ScriptObject[] args) { ((ScriptTable)args[0]).Remove(args[1].ObjectValue); return null; }
public object Call(ScriptObject[] args) { ((ScriptTable)args[0]).Clear(); return null; }
public static void SetObject(Dictionary <string, ScriptObject> variables, string key, ScriptObject obj) { variables[key] = obj.Assign(); }
public virtual ScriptObject Compute(Scorpio.Compiler.TokenType type, ScriptObject obj) { throw new ExecutionException(this.m_Script, this, string.Concat(new object[] { "类型[", this.Type, "]不支持运算符[", type, "]" })); }
internal void SetObjectInternal(string key, ScriptObject value) { m_GlobalTable.SetValue(key, value); }
public InteriorException(ScriptObject obj) { this.obj = obj; }
public virtual void SetValue(object key, ScriptObject value) { throw new ExecutionException(this.m_Script, this, string.Concat(new object[] { "类型[", this.Type, "]不支持设置变量[", key, "]" })); }
private ScriptObject Do(ScriptScriptFunction func) { ScriptObject ret = (ScriptObject)func.Call(); return(ret); }