protected static void AddEnum(Class cl, Json.Object mem, string name) { Enum e = new Enum(name); Json.Array members = (Json.Array)mem.GetValue("members"); Json.Object val; Json.Value v; string key; int idx; for (int i = 0; i < members.GetCount(); ++i) { idx = i; val = (Json.Object)members.GetValue(i); key = ((Json.String)val.GetValue("key")).GetValue(); if ((v = val.GetValue("value")) != null) { idx = Int32.Parse(((Json.String)v).GetValue()); } e.values.Add(key, idx); } cl.enums.Add(e); }
protected static void AddFunction(Class cl, Json.Object mem, string name) { Function f = new Function(name, ((Json.Object)mem.GetValue("returnType"))); Json.Value meta; if ((meta = mem.GetValue("meta")) != null) { Dictionary <string, Json.Value> .KeyCollection keys = ((Json.Object)meta).GetKeys(); if (keys.Contains("static") == true) { f.is_static = true; } } Json.Array args = (Json.Array)mem.GetValue("arguments"); Json.Object arg; Function.Arg farg; for (int i = 0; i < args.GetCount(); ++i) { arg = (Json.Object)args.GetValue(i); farg = new Function.Arg( ((Json.String)arg.GetValue("name")).GetValue(), ((Json.Object)arg.GetValue("type"))); f.args.Add(farg); } cl.funcs.Add(f); }
protected static void RecursiveParse(Json.Array root, List <Class> classes, string ns, string json) { bool verbose = false; Json.Value v; Json.String type, name; Json.Object cl; Json.Array members; Json.Object mem; Class new_class; string class_name; string mem_type, mem_name; for (int i = 0; i < root.GetCount(); ++i) { if ((v = root.GetValue(i)).IsType <Json.Object>() == true) { cl = (Json.Object)v; type = (Json.String)cl.GetValue("type"); if (type.GetValue() == "include") { continue; } if (type.GetValue() == "namespace") { string new_ns = ns + (ns.Length == 0 ? "" : "::") + ((Json.String)cl.GetValue("name")).GetValue(); RecursiveParse((Json.Array)cl.GetValue("members"), classes, new_ns, json); } if (type.GetValue() != "class") { continue; } if (cl.GetKeys().Contains("meta") == true) { if (((Json.Object)cl.GetValue("meta")).GetKeys().Contains("verbose") == true) { verbose = true; } } name = (Json.String)cl.GetValue("name"); class_name = name.GetValue(); Console.WriteLine("Parsing definition for: " + class_name); new_class = new Class(class_name); new_class.namespaces = ns; members = (Json.Array)cl.GetValue("members"); for (int j = 0; j < members.GetCount(); ++j) { mem = (Json.Object)members.GetValue(j); mem_type = ((Json.String)mem.GetValue("type")).GetValue(); mem_name = ((Json.String)mem.GetValue("name")).GetValue(); switch (mem_type) { case "function": AddFunction(new_class, mem, mem_name); break; case "enum": AddEnum(new_class, mem, mem_name); break; case "macro": CheckMacro(new_class, mem); break; } } Console.WriteLine("-- Lua name: " + new_class.lua_name); Console.WriteLine("-- Number of functions: " + new_class.funcs.Count); Console.WriteLine("-- Number of enums: " + new_class.enums.Count); Console.WriteLine("-- Namespaces: " + new_class.namespaces); classes.Add(new_class); } } if (verbose == true) { Console.Write(json); } }