Example #1
0
        private void FunctionListForm_Load(object sender, EventArgs e)
        {
            Icon = Properties.Resources.lua_file_format_symbol;

            // init func list
            LuaFile.FuncNode funcTree = Global.luaFile.FunctionTree;

            TreeNode root = new TreeNode(Global.GetFuncName(funcTree.Function));

            treeViewFunctions.Nodes.Add(root);

            AddChilds(ref root, funcTree);

            treeViewFunctions.ExpandAll();

            // choose current function
            if (!string.IsNullOrEmpty(_curFuncName))
            {
                TreeNode[] nodeFound = treeViewFunctions.Nodes.Find(_curFuncName, true);

                if (nodeFound.Length > 0)
                {
                    treeViewFunctions.SelectedNode = nodeFound[0];
                }
            }
        }
Example #2
0
        private void AddChilds(ref TreeNode curTreeNode, LuaFile.FuncNode curFuncNode)
        {
            foreach (var cur in curFuncNode.Children)
            {
                TreeNode newNode = new TreeNode(Global.GetFuncName(cur.Function));
                curTreeNode.Nodes.Add(newNode);

                foreach (var curChild in cur.Children)
                {
                    AddChilds(ref newNode, curChild);
                }
            }
        }
Example #3
0
        private void ExportFunction(LuaFile.FuncNode curNode, FileStream fs)
        {
            /// export current function
            // export function name
            byte[] buffer = Encoding.UTF8.GetBytes("@" + Global.fileName + ": " + curNode.Function.Header.LineDefined + "," + curNode.Function.Header.LastLineDefined + "\r\n");
            fs.Write(buffer, 0, buffer.Length);

            // export function header
            ExportFunctionHeader(curNode.Function.Header, fs);

            buffer = Encoding.UTF8.GetBytes("<Disassambling>\r\n");
            fs.Write(buffer, 0, buffer.Length);

            // export code
            for (int i = 0; i < curNode.Function.Code.Count; ++i)
            {
                LuaFile.Instruction curIns = curNode.Function.Code[i];

                // export index
                buffer = Encoding.UTF8.GetBytes("[" + i + "]\t");
                fs.Write(buffer, 0, buffer.Length);

                // export operation
                buffer = Encoding.UTF8.GetBytes(Enum.GetName(typeof(LuaFile.OpCode), curIns.Operation) + "\t\t");
                fs.Write(buffer, 0, buffer.Length);

                // export params
                buffer = Encoding.UTF8.GetBytes(GetParamString(curIns) + "\t");
                fs.Write(buffer, 0, buffer.Length);

                // change line
                buffer = Encoding.UTF8.GetBytes("\r\n");
                fs.Write(buffer, 0, buffer.Length);
            }

            buffer = Encoding.UTF8.GetBytes("\r\n");
            fs.Write(buffer, 0, buffer.Length);

            /// export children
            foreach (var cur in curNode.Children)
            {
                ExportFunction(cur, fs);
            }
        }