public static void Load(Script script) { ScriptTable Table = script.CreateTable(); Table.SetValue("encode", script.CreateFunction(new encode())); Table.SetValue("decode", script.CreateFunction(new decode(script))); script.SetObjectInternal("json", Table); }
public override ScriptObject Clone() { ScriptTable ret = Script.CreateTable(); ScriptObject obj = null; ScriptScriptFunction func = null; foreach (KeyValuePair <object, ScriptObject> pair in m_listObject) { if (pair.Value == this) { ret.m_listObject[pair.Key] = ret; } else { obj = pair.Value.Clone(); if (obj is ScriptScriptFunction) { func = (ScriptScriptFunction)obj; if (!func.IsStatic) { func.SetTable(ret); } } ret.m_listObject[pair.Key] = obj; } } return(ret); }
//解析文件结构 private void ParseLayout() { mFields.Clear(); mUsedCustoms.Clear(); for (int i = 0; i < mMaxColumn; ++i) { PackageField field = new PackageField(); field.Index = i; field.Comment = mDataTable[0][i]; //第0行是注释 field.Name = mDataTable[1][i]; //第1行是字段名 field.Default = mDataTable[3][i]; //第3行是字段默认值 var attribute = mDataTable[2][i]; //第2行是字段属性 Scorpio.Script script = new Scorpio.Script(); script.LoadLibrary(); if (string.IsNullOrEmpty(attribute)) { field.Attribute = script.CreateTable(); } else { field.Attribute = (script.LoadString("return {" + attribute + "}") as ScriptTable) ?? script.CreateTable(); } string columnType = mDataTable[4][i]; //第4行是字段类型 string fieldType = ""; if (columnType.StartsWith(Util.ArrayString)) { field.Array = true; int iFinalIndex = Util.ArrayString.Length; fieldType = columnType.Substring(iFinalIndex, columnType.Length - iFinalIndex); } else { field.Array = false; fieldType = columnType; } field.Type = fieldType; bool basic = BasicUtil.HasType(fieldType); if (!basic && !mCustoms.ContainsKey(fieldType) && !mEnums.ContainsKey(fieldType)) { throw new System.Exception(string.Format("第[{0}]列的 字段类型[{1}] 不能识别", Util.GetLineName(i), columnType)); } if (i == 0 && (field.Array == true || field.Info.BasicIndex != BasicEnum.INT32)) { throw new System.Exception("第一列的数据类型必须为int32类型"); } field.Enum = mEnums.ContainsKey(fieldType); //保存使用的自定义结构 if (!basic && !field.Enum && !mUsedCustoms.Contains(fieldType)) { mUsedCustoms.Add(fieldType); } mFields.Add(field); } if (mFields.Count == 0) { throw new System.Exception("字段个数为0"); } mKeyName = mFields[0].Name; }
public static void Load(Script script) { ScriptTable Table = script.CreateTable(); Table.SetValue("count", script.CreateFunction(new count(script))); Table.SetValue("isparams", script.CreateFunction(new isparams(script))); Table.SetValue("isstatic", script.CreateFunction(new isstatic(script))); Table.SetValue("getparams", script.CreateFunction(new getparams(script))); script.SetObjectInternal("func", Table); }
public static void Load(Script script) { ScriptTable Table = script.CreateTable(); Table.SetValue("count", script.CreateFunction(new count())); Table.SetValue("clear", script.CreateFunction(new clear())); Table.SetValue("remove", script.CreateFunction(new remove())); Table.SetValue("containskey", script.CreateFunction(new containskey())); Table.SetValue("keys", script.CreateFunction(new keys())); Table.SetValue("values", script.CreateFunction(new values())); script.SetObjectInternal("table", Table); }
public static void Load(Script script) { ScriptTable Table = script.CreateTable(); Table.SetValue("PI", script.CreateDouble(PI)); Table.SetValue("Deg2Rad", script.CreateDouble(Deg2Rad)); Table.SetValue("Rad2Deg", script.CreateDouble(Rad2Deg)); Table.SetValue("Epsilon", script.CreateDouble(Epsilon)); Table.SetValue("min", script.CreateFunction(new min())); Table.SetValue("max", script.CreateFunction(new max())); Table.SetValue("abs", script.CreateFunction(new abs())); Table.SetValue("floor", script.CreateFunction(new floor())); Table.SetValue("clamp", script.CreateFunction(new clamp())); Table.SetValue("sqrt", script.CreateFunction(new sqrt())); Table.SetValue("pow", script.CreateFunction(new pow())); script.SetObjectInternal("math", Table); }
public static void Load(Script script) { ScriptTable Table = script.CreateTable(); Table.SetValue("format", script.CreateFunction(new format())); Table.SetValue("substring", script.CreateFunction(new substring())); Table.SetValue("length", script.CreateFunction(new length())); Table.SetValue("tolower", script.CreateFunction(new tolower())); Table.SetValue("toupper", script.CreateFunction(new toupper())); Table.SetValue("trim", script.CreateFunction(new trim())); Table.SetValue("replace", script.CreateFunction(new replace())); Table.SetValue("isnullorempty", script.CreateFunction(new isnullorempty())); Table.SetValue("indexof", script.CreateFunction(new indexof())); Table.SetValue("lastindexof", script.CreateFunction(new lastindexof())); Table.SetValue("startswith", script.CreateFunction(new startswith())); Table.SetValue("endswith", script.CreateFunction(new endswith())); Table.SetValue("contains", script.CreateFunction(new contains())); script.SetObjectInternal("string", Table); }
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(Script, "table [+] 操作只支持两个table " + value.Type); } ScriptTable ret = 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.IsStatic) { 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.IsStatic) { func.SetTable(ret); } } ret.m_listObject[pair.Key] = obj; } return(ret); }
public static void Load(Script script) { ScriptTable Table = script.CreateTable(); Table.SetValue("count", script.CreateFunction(new count())); Table.SetValue("insert", script.CreateFunction(new insert())); Table.SetValue("add", script.CreateFunction(new add())); Table.SetValue("remove", script.CreateFunction(new remove())); Table.SetValue("removeat", script.CreateFunction(new removeat())); Table.SetValue("clear", script.CreateFunction(new clear())); Table.SetValue("contains", script.CreateFunction(new contains())); Table.SetValue("sort", script.CreateFunction(new sort())); Table.SetValue("indexof", script.CreateFunction(new indexof())); Table.SetValue("lastindexof", script.CreateFunction(new lastindexof())); Table.SetValue("first", script.CreateFunction(new first())); Table.SetValue("last", script.CreateFunction(new last())); Table.SetValue("pop", script.CreateFunction(new popfirst())); Table.SetValue("safepop", script.CreateFunction(new safepopfirst())); Table.SetValue("popfirst", script.CreateFunction(new popfirst())); Table.SetValue("safepopfirst", script.CreateFunction(new safepopfirst())); Table.SetValue("poplast", script.CreateFunction(new poplast())); Table.SetValue("safepoplast", script.CreateFunction(new safepoplast())); script.SetObjectInternal("array", Table); }