/// <summary> /// 标准lua脚本 /// </summary> /// <returns></returns> public override string ToString() { string codeStr = ""; if (isLabel) { codeStr += "::" + label + ":: "; } codeStr += opcode + "(" + info.ToString(); foreach (var param in paramDatas) { if (ScriptEntity.IsString(param.type)) { codeStr += ", " + "\"" + param.valueString.Replace("\n", @"\n") + "\""; } else if (param.type == DataType.Position) { codeStr += ", " + "\"" + param.valueString + "\""; } else { codeStr += ", " + param.valueString; } } codeStr += ")"; return(codeStr); }
/// <summary> /// 可导入lua的加载,转成CodeLine /// </summary> /// <param name="codeStr"></param> public CodeLine(string codeStr) { List <string> tokens = new List <string>(); string token = ""; bool isStr = false; int i = 0; while (i < codeStr.Length) { if (codeStr[i] == '\"') { isStr = !isStr; } if (!isStr && (codeStr[i] == '(' || codeStr[i] == '{' || codeStr[i] == ')' || codeStr[i] == '}' || codeStr[i] == ',' || codeStr[i] == ' ')) { token = token.Trim(); if (token != "") { tokens.Add(token); token = ""; } if (!(codeStr[i] == ',' || codeStr[i] == ' ')) { tokens.Add(codeStr[i].ToString()); } } else { token += codeStr[i]; } i++; } token = token.Trim(); if (token != "") { tokens.Add(token); } paramDatas = new List <ParamData>(); bool readParam = false; string tempStr = ""; i = 0; while (i < tokens.Count) { if (!readParam) { if (tokens[i][0] == ':') { isLabel = true; label = tokens[i].Substring(2, tokens[i].Length - 4); i++; // ( } if (opcode == null) { opcode = tokens[i]; } if (tokens[i] == "{") { i++; // { CodeInfo info = new CodeInfo(0); List <UInt16> datas = new List <UInt16>(); while (tokens[i] != "}") { datas.Add(Convert.ToUInt16(tokens[i++])); } info.count = datas.Count; info.data = datas.ToArray(); this.info = info; readParam = true; // i = } } } else { ParamData param = new ParamData(); if (tokens[i] == ")") { break; } else if (tokens[i] == "(") { i++; DataType type = ScriptEntity.ToDataType(tokens[i++]); i++; if (tokens[i][0] == '\"') { tempStr = tokens[i].Substring(1, tokens[i].Length - 2).Replace(@"\n", "\n");; param = ScriptEntity.ToParamData(tempStr, type); if (type == DataType.Position) { isPosition = true; param.valueOp = tempStr; } } else { param = ScriptEntity.ToParamData(tokens[i], type); } // i = ) } else if (tokens[i].Length >= 4 && tokens[i].Substring(0, 2) == "0x") { param = ScriptEntity.ToParamData(tokens[i], DataType.Byte2); } else { param = ScriptEntity.ToParamData(tokens[i], DataType.UInt16); } paramDatas.Add(param); } i++; } }