Ejemplo n.º 1
0
        public LuaFunctionInfo FetchFunctionInfo(int pageid, string name)
        {
            Console.WriteLine($"    Fetching function: {name} - {pageid}");

            var root = FetchPage(pageid);
            var info = LuaFunctionInfo.ConvertRoot(root);

            if (info != null)
            {
                info.Name = name;
            }
            return(info);
        }
Ejemplo n.º 2
0
        public List <LuaFunctionInfo> FetchFunctionInfo(Dictionary <int, string> dict)
        {
            Console.WriteLine("    Fetching functions - " + String.Join(", ", dict.Values));
            var pages = FetchPages(dict.Keys.ToArray());
            var infos = new List <LuaFunctionInfo>();

            foreach (var entry in pages)
            {
                var info = LuaFunctionInfo.ConvertRoot(entry.Value);
                if (info != null)
                {
                    info.Name = dict[entry.Key];
                    infos.Add(info);
                }
            }
            return(infos);
        }
Ejemplo n.º 3
0
        public static LuaFunctionInfo ConvertRoot(XRoot root)
        {
            bool isFunction = false;
            var  info       = new LuaFunctionInfo();

            foreach (var template in root.Templates)
            {
                var translated = TranslateTemplate.Translate(template);
                if (translated is FuncTemplate func)
                {
                    isFunction       = true;
                    info.Description = func.Description;
                }
                else if (translated is ArgTemplate arg)
                {
                    var argumentDeclaration = new IDescribeArgument {
                        Name = arg.Name, Type = TranslateType(arg.Type), Description = arg.Desc
                    };
                    if (!string.IsNullOrWhiteSpace(arg.Default))
                    {
                        argumentDeclaration.Attributes.Add(new CodeAttributeDeclaration(nameof(OptionalAttribute)));
                    }
                    info.Arguments.Add(argumentDeclaration);
                }
                else if (translated is RetTemplate ret)
                {
                    info.Returns.Add(new IDescribeReturn {
                        Type = TranslateType(ret.Type), Description = ret.Desc
                    });
                }
                else if (translated is ExampleTemplate example)
                {
                    info.Examples.Add(example);
                }
            }
            if (!isFunction)
            {
                return(null);
            }
            return(info);
        }