Beispiel #1
0
    /// <summary>
    /// Lua 将解析到的xml生成string,并赋值到sb
    /// </summary>
    void sWriteLuaFileContent(StringBuilder sb, DataStructFileData fileData)
    {
        List <string> declareStringList = new List <string>();
        List <string> ctorStringList    = new List <string>();
        List <string> packStringList    = new List <string>();
        List <string> unpackStringList  = new List <string>();

        for (int i = 0; i < fileData.mParamList.Count; ++i)
        {
            ParamDataOutString outString = CmdParserComUitls.CmdParamParserDeclare_Lua(fileData.mParamList[i], fileData.mClassName);
            declareStringList.AddRange(outString.mOutDeclareString.ToArray());
            ctorStringList.AddRange(outString.mOutCtorString.ToArray());
            packStringList.AddRange(outString.mOutPackString.ToArray());
            unpackStringList.AddRange(outString.mOutUnpackString.ToArray());
        }
        if (fileData.mFather == "NULL" || fileData.mFather == null)
        {
            sb.AppendLine(fileData.mClassName + " = class(\"" + fileData.mClassName + "\");");
        }
        else
        {
            sb.AppendLine(fileData.mClassName + " = class(\"" + fileData.mClassName + "\"," + fileData.mFather + ");");
        }
        sb.AppendLine();
        //声明
        for (int j = 0; j < declareStringList.Count; ++j)
        {
            sb.AppendLine("\t" + declareStringList[j].Replace("self", fileData.mClassName));
        }
        sb.AppendLine();
        //ctor
        sb.Append("function " + fileData.mClassName + ":ctor()");
        sb.AppendLine();
        for (int i = 0; i < ctorStringList.Count; i++)
        {
            sb.Append("\n" + ctorStringList[i]);
        }
        sb.Append("\nend\n");
        sb.AppendLine();
        //PackData 打包
        sb.AppendLine("function " + fileData.mClassName + ":PackData(byteBuffer)");
        if (fileData.mFather != "NULL" & fileData.mFather != null)
        {
            sb.AppendLine("\t " + fileData.mClassName + ".super:PackData(byteBuffer);");
        }
        for (int k = 0; k < packStringList.Count; ++k)
        {
            sb.AppendLine("\t\t" + packStringList[k].Replace("self.byteBuffer", "byteBuffer"));
        }
        sb.Append("end");
        sb.AppendLine();
        //UnPackData
        sb.AppendLine("function " + fileData.mClassName + ":UnPackData(byteBuffer)");
        if (fileData.mFather != "NULL" & fileData.mFather != null)
        {
            sb.AppendLine("\t " + fileData.mClassName + ".super.UnPackData(self,byteBuffer);");
        }
        for (int m = 0; m < unpackStringList.Count; ++m)
        {
            sb.AppendLine("\t\t" + unpackStringList[m].Replace("self.byteBuffer", "byteBuffer"));
        }
        sb.Append("\nend\n");
        sb.AppendLine();
    }
Beispiel #2
0
    public void sWriteLuaFileContent(string fileType, CmdStructFileData fileData)
    {
        StringBuilder sb = new StringBuilder();

        NetCmdXmlParser.sWriteLuaFileHeadComment(sb, fileData.mClassName, fileData.mDescribe);      //生成注释的文件头
        //所需XML数据
        List <string> declareStringList = new List <string>();
        List <string> packStringList    = new List <string>();
        List <string> unpackStringList  = new List <string>();
        List <string> ctorStringList    = new List <string>(); //初始化字符串

        for (int i = 0; i < fileData.mCmdList.Count; ++i)
        {
            ParamDataOutString outString = CmdParserComUitls.CmdParamParserDeclare_Lua(fileData.mCmdList[i], fileData.mClassName, true);
            declareStringList.AddRange(outString.mOutDeclareString.ToArray());
            packStringList.AddRange(outString.mOutPackString.ToArray());
            unpackStringList.AddRange(outString.mOutUnpackString.ToArray());
            ctorStringList.AddRange(outString.mOutCtorString.ToArray());
        }
        //lua的文件直接生成到对应根目录下,防止lua打包时生成过多零碎文件

        /*
         * string filePathName = "";
         * if (fileData.mPathName != null)
         * {
         *  filePathName = fileData.mPathName + "/";
         * }
         */
        string outFilePath = "";  //生成文件位置
        bool   _isWrite    = false;

        switch (fileType)
        {
        case "Lua_C":
            outFilePath = NetCmdXmlParser.targetLuaFileBasePath + cmdOutFilePath_C + fileData.mClassName + "_C.lua";
            sWriteLuaFileContent_C(sb, fileData, declareStringList, packStringList);
            _isWrite = true;
            break;

        case "Lua_S":
            outFilePath = NetCmdXmlParser.targetLuaFileBasePath + cmdOutFilePath_S + fileData.mClassName + "_S.lua";
            LuaScriptParserTool.AddLuaRequireString(cmdOutFilePathName_S + "." + fileData.mClassName + "_S");
            sWriteLuaFileContent_S(sb, fileData, declareStringList, unpackStringList, ctorStringList);
            _isWrite = true;
            break;

        case "Lua_Handler":
            outFilePath = NetCmdXmlParser.targetLuaFileBasePath + cmdOutFilePath_Handler + fileData.mClassName + "_Handler.lua";
            LuaScriptParserTool.AddLuaRequireString(cmdOutFilePathName_Handler + "." + fileData.mClassName + "_Handler");
            if (!File.Exists(outFilePath))
            {
                sWriteLuaFileContent_Handler(sb, fileData);
                _isWrite = true;
            }
            else
            {
                return;
            }
            break;
        }
        if (_isWrite)
        {
            NetCmdXmlParser.sWriteStringToFile(outFilePath, sb);
        }
    }