Esempio n. 1
0
        public void Help(string command)
        {
            // Check if the command is a function name
            if (_lua.Functions.Contains(command))
            {
                LuaFunctionDescriptor func = (LuaFunctionDescriptor)_lua.Functions[command];

                // Display basic help message
                txtResult.Text += "Help for " + command + ":\n=========";

                for (int i = 0; i <= command.Length; i++)
                {
                    txtResult.Text += "=";
                }

                txtResult.Text += "\n" + func.FunctionFullDocumentation + "\n\n";

                return;
            }

            // Check if the command is a package name
            if (command.IndexOf(".") == -1)
            {
                // Check if the package exists
                if (_lua.Packages.ContainsKey(command))
                {
                    LuaPackageDescriptor pkg = (LuaPackageDescriptor)_lua.Packages[command];

                    DisplayPackageHelp(pkg);

                    return;
                }
                else
                {
                    txtResult.Text += "No such function or package: " + command + "\n\n";

                    return;
                }
            }

            // Determine the path to the function name
            string[] parts = command.Split('.');

            // Check if the package exists
            if (!_lua.Packages.ContainsKey(parts[0]))
            {
                txtResult.Text += "No such function or package: " + command + "\n\n";

                return;
            }

            LuaPackageDescriptor desc = (LuaPackageDescriptor)_lua.Packages[parts[0]];

            // Check if the function exists within the package
            if (!desc.HasFunction(parts[1]))
            {
                txtResult.Text += "Package " + parts[0] + " doesn't have a " + parts[1] + " function.\n\n";

                return;
            }

            // Display basic help message
            txtResult.Text += "Help for " + command + ":\n=========";

            for (int i = 0; i <= command.Length; i++)
            {
                txtResult.Text += "=";
            }

            txtResult.Text += "\n" + desc.PackageName + "." + desc.WriteHelp(parts[1]) + "\n\n";
        }