Exemple #1
0
 private void DocumentCommands(LuaCommandModule commandModule)
 {
     m_helpString.AppendFormat("<size=20><b>{0}</b></size>\n", commandModule.Name.ToUpper());
     DocumentProperties(commandModule);
     DocumentMethods(commandModule);
     m_helpString.AppendLine();
 }
Exemple #2
0
        private void DocumentProperties(LuaCommandModule commandModule)
        {
            Type type       = commandModule.GetType();
            var  properties = from pi in type.GetProperties(BindingFlags.Public | BindingFlags.Instance)
                              select pi;

            foreach (var property in properties)
            {
                var luaCommandAttribute = ReflectionUtils.GetCustomAttribute <LuaCommandAttribute>(property);
                if (luaCommandAttribute != null)
                {
                    m_helpString.Append("\u2022 <color=#3255FFFF>");
                    m_helpString.Append(commandModule.Name);
                    m_helpString.Append('.');

                    m_helpString.Append(property.Name);
                    m_helpString.Append(" : ");

                    string typeName = property.PropertyType.Name;
                    if (TypeNameLookup.ContainsKey(typeName))
                    {
                        typeName = TypeNameLookup[typeName];
                    }

                    m_helpString.Append(typeName);
                    m_helpString.Append("</color>");

                    m_helpString.AppendFormat(" - {0}", luaCommandAttribute.Help);
                    m_helpString.Append('\n');
                }
            }
        }
Exemple #3
0
        private void Awake()
        {
            m_helpString = new StringBuilder();
            m_helpString.AppendLine("\u2022 <color=#3255FFFF>help</color> - Prints a list of available commands.");
            m_helpString.AppendLine("\u2022 <color=#3255FFFF>clear</color> - Removes all log messages.");
            m_helpString.AppendLine("\u2022 <color=#3255FFFF>feedback</color> - Opens the feedback form.");
            m_helpString.AppendLine("\u2022 <color=#3255FFFF>reset</color> - Resets debug console layout.");
            m_helpString.AppendLine();

            m_luaScript = new Script(CoreModules.Preset_HardSandbox);
            m_luaScript.Options.DebugPrint = message => Debug.Log(message);

            Assembly assembly = ReflectionUtils.GetAssembly(GetType());
            Type     cpType   = typeof(LuaCommandModule);

            var types = from tp in assembly.GetTypes()
                        where !ReflectionUtils.IsAbstract(tp) && cpType.IsAssignableFrom(tp)
                        select tp;

            foreach (var type in types)
            {
                LuaCommandModule instance = Activator.CreateInstance(type) as LuaCommandModule;
                if (instance != null)
                {
                    AddCommands(instance);
                }
            }

            DebugConsole.CommandParser = this;
        }
Exemple #4
0
        private void DocumentMethods(LuaCommandModule commandModule)
        {
            Type type    = commandModule.GetType();
            var  methods = from mi in type.GetMethods(BindingFlags.Public | BindingFlags.Instance)
                           select mi;

            foreach (var method in methods)
            {
                var luaCommandAttribute = ReflectionUtils.GetCustomAttribute <LuaCommandAttribute>(method);
                if (luaCommandAttribute != null)
                {
                    m_helpString.Append("\u2022 <color=#3255FFFF>");
                    m_helpString.Append(commandModule.Name);
                    m_helpString.Append('.');

                    m_helpString.Append(method.Name);
                    m_helpString.Append('(');

                    ParameterInfo[] parameters = method.GetParameters();
                    for (int i = 0; i < parameters.Length; i++)
                    {
                        string typeName = parameters[i].ParameterType.Name;
                        if (TypeNameLookup.ContainsKey(typeName))
                        {
                            typeName = TypeNameLookup[typeName];
                        }

                        m_helpString.Append(typeName);
                        m_helpString.Append(' ');
                        m_helpString.Append(parameters[i].Name);
                        if (i < parameters.Length - 1)
                        {
                            m_helpString.Append(", ");
                        }
                    }

                    m_helpString.Append(")</color>");

                    m_helpString.AppendFormat(" - {0}", luaCommandAttribute.Help);
                    m_helpString.Append('\n');
                }
            }
        }
Exemple #5
0
 private void AddCommands(LuaCommandModule commandModule)
 {
     commandModule.Register();
     m_luaScript.Globals[commandModule.Name] = commandModule;
     DocumentCommands(commandModule);
 }