public void GenerateEnum(ClassDescription cd, string path) { Lua4NetSerializer serializer = new Lua4NetSerializer(0); ProxyGenerator.GenerateEnum(cd, serializer); string fullpath = Path.Combine(path, cd.LuaFileName); SaveAsFile(fullpath, serializer.ToString()); }
public void GenerateProxy(string path,ScriptableXml sxml) { List<string> allfile = new List<string>(); GenerateProxyImpl(csd => { if (csd.IsEnum) { GenerateEnum(csd, path); allfile.Add(csd.LuaFileName); } else { Lua4NetSerializer serializer = new Lua4NetSerializer(0); ProxyGenerator.Generate(csd, serializer); string content = serializer.ToString(); Console.WriteLine(content); string filename = csd.LuaFileName; string fullpath = Path.Combine(path, filename); allfile.Add(filename); SaveAsFile(fullpath, content); } }); Lua4NetSerializer rs = new Lua4NetSerializer(0); rs.NewLine(); List<string> allNamespaces = new List<string>(); sxml.Assembly.ForEach(s => { if (!string.IsNullOrEmpty(s.Namespace)) { GetNamespace(s.Namespace).ForEach(ns=> { if (!allNamespaces.Contains(ns)) { allNamespaces.Add(ns); } }); } }); if (allNamespaces.Count > 0) { allNamespaces.ForEach(n => { rs.NewLine(n + " = { }"); }); } allfile.ForEach(s => { char ch1 = '\\'; char ch2 = '/'; s = s.Replace(ch1, ch2); rs.NewLine(string.Format("dofile('{0}')", s)); }); rs.NewLine("print('load Lua4NetRoot done!')"); string rp = Path.Combine(path, "Lua4NetRoot.lua"); SaveAsFile(rp, rs.ToString()); }
private void Generate(string path, ClassDescription cd, Func<ClassDescription, Lua4NetSerializer, string> GetContent) { Lua4NetSerializer serializer = new Lua4NetSerializer(0); List<string> namespaces = new List<string>() { "System", "Lua4Net" }; GenerateNamespace(cd, ns => { foreach (string n in ns) { if (!namespaces.Contains(n)) namespaces.Add(n); } }); namespaces.ForEach(n => { serializer.NewLine(string.Format("using {0};", n)); }); serializer.NewLine(); serializer.NewLine(string.Format("namespace {0}", "Lua4Net")); serializer.BeginBlock("{"); string file = GetContent(cd, serializer); serializer.EndBlock("}"); string fullpath = Path.Combine(path, file); string content = serializer.ToString(); Console.WriteLine(content); SaveAsFile(fullpath, content); }
public void GenerateServantRoot(string path) { Lua4NetSerializer serializer = new Lua4NetSerializer(0); serializer.NewLine("using System;"); serializer.NewLine("namespace Lua4Net"); serializer.BeginBlock("{"); serializer.NewLine(); serializer.NewLine("public class Lua4NetRoot : LuaRegister"); serializer.BeginBlock("{"); serializer.NewLine("private LuaRegister[] allRegister = "); serializer.BeginBlock("{"); for (int i = 0; i < allServants.Count; ++i) { serializer.NewLine(string.Format("new {0}()", allServants[i])); if (i != (allServants.Count - 1)) serializer.Apppend(","); } serializer.EndBlock("};"); serializer.NewLine(); serializer.NewLine("public override void Register(IntPtr l)"); serializer.BeginBlock("{"); serializer.NewLine("foreach(LuaRegister r in allRegister)"); serializer.BeginBlock("{"); serializer.NewLine("r.Register(l);"); serializer.EndBlock("}"); serializer.EndBlock("}"); serializer.EndBlock("}"); serializer.EndBlock("}"); string fullpath = Path.Combine(path, "Lua4NetRoot.cs"); string content = serializer.ToString(); SaveAsFile(fullpath, content); }