public static void BuildDelegateWrapperForAOT(IEnumerable <Types> deltypes, string file) { CodeCompileUnit cu = new CodeCompileUnit(); CodeNamespace ns = new CodeNamespace("Capstones.LuaWrap.DelWrapperAOT"); cu.Namespaces.Add(ns); CodeTypeDeclaration type_Entry = new CodeTypeDeclaration("DelWrapperAOTEntry"); type_Entry.TypeAttributes = TypeAttributes.Public | TypeAttributes.Class; ns.Types.Add(type_Entry); CodeMemberMethod method_Entry = new CodeMemberMethod(); method_Entry.Name = "Entry"; method_Entry.Attributes = MemberAttributes.Private | MemberAttributes.Static; method_Entry.ReturnType = new CodeTypeReference(typeof(void)); type_Entry.Members.Add(method_Entry); method_Entry.Statements.Add(new CodeSnippetStatement("#pragma warning disable CS0618")); foreach (var deltype in deltypes) { var delpars = deltype; if (delpars[0] == typeof(void)) { var wrapper = CapsLuaDelegateGenerator.GetWrapperType(delpars[0], delpars.Count - 1); if (wrapper != null) { CodeTypeReference wtype = new CodeTypeReference(wrapper); for (int i = 1; i < delpars.Count; ++i) { wtype.TypeArguments.Add(delpars[i]); } CodeObjectCreateExpression exp_new = new CodeObjectCreateExpression(wtype); method_Entry.Statements.Add(exp_new); } } else { var wrapper = CapsLuaDelegateGenerator.GetWrapperType(delpars[0], delpars.Count - 1); if (wrapper != null) { CodeTypeReference wtype = new CodeTypeReference(wrapper); for (int i = 0; i < delpars.Count; ++i) { wtype.TypeArguments.Add(delpars[i]); } CodeObjectCreateExpression exp_new = new CodeObjectCreateExpression(wtype); method_Entry.Statements.Add(exp_new); } } } method_Entry.Statements.Add(new CodeSnippetStatement("#pragma warning restore CS0618")); Microsoft.CSharp.CSharpCodeProvider csharpcodeprovider = new Microsoft.CSharp.CSharpCodeProvider(); using (var sw = PlatDependant.OpenWriteText(file)) { csharpcodeprovider.GenerateCodeFromCompileUnit(cu, sw, new System.CodeDom.Compiler.CodeGeneratorOptions()); } }
public static void SaveCachedAtlas() { var jo = new JSONObject(JSONObject.Type.OBJECT); var joc = new JSONObject(JSONObject.Type.ARRAY); jo["atlas"] = joc; foreach (var asset in _CachedAtlasRev.Keys) { joc.Add(asset); } //joc = new JSONObject(JSONObject.Type.OBJECT); //jo["tex"] = joc; //foreach (var kvp in _TexInAtlas) //{ // var name = kvp.Key; // var list = kvp.Value; // if (list != null && list.Count > 0) // { // var jlist = new JSONObject(JSONObject.Type.ARRAY); // joc[name] = jlist; // for (int i = 0; i < list.Count; ++i) // { // jlist.Add(list[i]); // } // } //} using (var sw = PlatDependant.OpenWriteText("EditorOutput/Runtime/atlas.txt")) { sw.Write(jo.ToString(true)); } }
private static void SaveCachedPHFonts() { var jo = new JSONObject(JSONObject.Type.OBJECT); var phfontsnode = new JSONObject(_PHFontNameToAssetName); jo["phfonts"] = phfontsnode; using (var sw = PlatDependant.OpenWriteText("EditorOutput/Runtime/phfont.txt")) { sw.Write(jo.ToString(true)); } }
public void OnSuccess() { var jo = new JSONObject(JSONObject.Type.OBJECT); var joc = new JSONObject(_NewMap); jo["tex"] = joc; var cachefile = _Output + "/res/inatlas.txt"; using (var sw = PlatDependant.OpenWriteText(cachefile)) { sw.Write(jo.ToString(true)); } }
private static void SaveCachedReplacement() { var jo = new JSONObject(JSONObject.Type.OBJECT); var rnode = new JSONObject(JSONObject.Type.ARRAY); jo["replacements"] = rnode; foreach (var asset in _FontReplacementDescs.Keys) { rnode.list.Add(new JSONObject(JSONObject.Type.STRING) { str = asset }); } using (var sw = PlatDependant.OpenWriteText("EditorOutput/Runtime/rfont.txt")) { sw.Write(jo.ToString(true)); } }
void OnGUI() { GUILayout.BeginVertical(); GUILayout.Label("Which precompiler symbol would you like to define?"); _Symbol = GUILayout.TextField(_Symbol); if (GUILayout.Button("OK")) { if (string.IsNullOrEmpty(_Symbol)) { EditorUtility.DisplayDialog("Error", "Empty Symbol!", "OK"); } else if (_Symbol.EndsWith("_")) { EditorUtility.DisplayDialog("Error", "Symbol should not end with _", "OK"); } else { if (System.IO.Directory.Exists("Assets/Mods/" + _Symbol)) { EditorUtility.DisplayDialog("Warning", "It seems that the mod has been already created.", "OK"); } else { var descdir = "Assets/Mods/" + _Symbol + "/Resources"; System.IO.Directory.CreateDirectory(descdir); AssetDatabase.ImportAsset(descdir); var desc = ScriptableObject.CreateInstance <CapsModDesc>(); desc.Mod = _Symbol; AssetDatabase.CreateAsset(desc, "Assets/Mods/" + _Symbol + "/Resources/resdesc.asset"); var sympath = "Assets/Mods/" + _Symbol + "/Link/mcs.rsp"; using (var sw = PlatDependant.OpenWriteText(sympath)) { sw.Write("-define:"); sw.WriteLine(_Symbol); } CapsModEditor.CheckModsVisibility(); DistributeSelectWindow.Init(); } Close(); } } GUILayout.EndVertical(); }
public static void SaveManifest(CapsResManifest mani, string file) { var tmpfile = file + ".tmp"; using (var sw = PlatDependant.OpenWriteText(tmpfile)) { if (mani != null && mani.Root != null) { Stack <Pack <int, CapsResManifestNode> > candis = new Stack <Pack <int, CapsResManifestNode> >(); candis.Push(new Pack <int, CapsResManifestNode>(0, mani.Root)); while (candis.Count > 0) { var ppair = candis.Pop(); var plvl = ppair.t1; var parent = ppair.t2; for (int i = 0; i < plvl; ++i) { sw.Write("*"); } sw.WriteLine(parent.PPath ?? ""); var children = parent.Children; if (children != null) { var clvl = plvl + 1; for (int i = children.Count - 1; i >= 0; --i) { var child = children.Values[i]; candis.Push(new Pack <int, CapsResManifestNode>(clvl, child)); } } } } } PlatDependant.MoveFile(tmpfile, file); }
public void OnPreprocessBuild(BuildTarget target, string path) { using (var sw = PlatDependant.OpenWriteText("Assets/StreamingAssets/res/index.txt")) { var files = PlatDependant.GetAllFiles("Assets/StreamingAssets/res/mani/"); if (files != null) { for (int i = 0; i < files.Length; ++i) { var file = files[i]; if (file.EndsWith(".m.ab")) { var key = file.Substring("Assets/StreamingAssets/res/mani/".Length, file.Length - "Assets/StreamingAssets/res/mani/".Length - ".m.ab".Length); sw.WriteLine(key); } } } } using (var sw = PlatDependant.OpenWriteText("Assets/StreamingAssets/res/builtin-scenes.txt")) { var scenes = EditorBuildSettings.scenes; int index = 0; for (int i = 0; i < scenes.Length; ++i) { var sceneinfo = scenes[i]; if (sceneinfo.enabled) { var guid = sceneinfo.guid.ToString(); var scenepath = AssetDatabase.GUIDToAssetPath(guid); sw.Write(scenepath); sw.Write("|"); sw.WriteLine(index++); } } } }
public static void CheckRes(string output) { // generate build work List <CapsResBuilder.IResBuilderEx> allExBuilders = CapsResBuilder.ResBuilderEx; for (int i = 0; i < allExBuilders.Count; ++i) { allExBuilders[i].Prepare(null); } Dictionary <string, CapsResBuilder.CapsResBuildWork> buildwork = new Dictionary <string, CapsResBuilder.CapsResBuildWork>(); var gwork = CapsResBuilder.GenerateBuildWorkAsync(buildwork, null, null); while (gwork.MoveNext()) { ; } for (int i = 0; i < allExBuilders.Count; ++i) { allExBuilders[i].Cleanup(); } // parse asset list in each reskey (m-XXX-d-YYY) Dictionary <string, List <string> > reskey2assetlist = new Dictionary <string, List <string> >(); Dictionary <string, string> asset2reskey = new Dictionary <string, string>(); HashSet <string> nodepassets = new HashSet <string>(); foreach (var buildmodwork in buildwork) { var mod = buildmodwork.Key; var work = buildmodwork.Value; var manifests = work.Manifests; for (int i = 0; i < manifests.Length; ++i) { var mani = manifests[i]; var opmod = mani.MFlag; var dist = mani.DFlag ?? ""; var reskey = "m-" + opmod + "-d-" + dist; List <string> list; if (!reskey2assetlist.TryGetValue(reskey, out list)) { list = new List <string>(); reskey2assetlist[reskey] = list; } for (int j = 0; j < work.ABs.Length; ++j) { var abinfo = work.ABs[j]; var abname = abinfo.assetBundleName; if (abname.EndsWith(".=.ab")) { for (int k = 0; k < abinfo.assetNames.Length; ++k) { var asset = abinfo.assetNames[k]; nodepassets.Add(asset); } continue; } if (!string.IsNullOrEmpty(abinfo.assetBundleVariant)) { abname += "." + abinfo.assetBundleVariant; } if (CapsResBuilder.IsBundleInModAndDist(abname, opmod, dist)) { list.AddRange(abinfo.assetNames); for (int k = 0; k < abinfo.assetNames.Length; ++k) { var asset = abinfo.assetNames[k]; asset2reskey[asset] = reskey; } } } } } // parse dep and ref Dictionary <string, HashSet <string> > resdep = new Dictionary <string, HashSet <string> >(); Dictionary <string, HashSet <string> > resref = new Dictionary <string, HashSet <string> >(); foreach (var kvpassetreskey in asset2reskey) { var asset = kvpassetreskey.Key; //var reskey = kvpassetreskey.Value; HashSet <string> deplist; if (!resdep.TryGetValue(asset, out deplist)) { deplist = new HashSet <string>(); resdep[asset] = deplist; } var deps = GetDependencies(asset); for (int i = 0; i < deps.Length; ++i) { var dep = deps[i]; deplist.Add(dep); HashSet <string> reflist; if (!resref.TryGetValue(dep, out reflist)) { reflist = new HashSet <string>(); resref[dep] = reflist; } reflist.Add(asset); } } using (var sw = PlatDependant.OpenWriteText(output)) { // check cross mod/dist ref bool crossdepfound = false; foreach (var kvpdep in resdep) { var asset = kvpdep.Key; var deps = kvpdep.Value; var assetkey = asset2reskey[asset]; foreach (var dep in deps) { if (!asset2reskey.ContainsKey(dep)) { continue; // not in build? check later. } var depkey = asset2reskey[dep]; if (assetkey == depkey) { continue; // the same package } else if (depkey == "m--d-") { continue; // any asset can refer the assets in main package. } else if (depkey.EndsWith("-d-") && assetkey.StartsWith(depkey)) { continue; // the dist package refer non-dist package. } else if (depkey.StartsWith("m--d-") && assetkey.EndsWith(depkey.Substring(2))) { continue; // the mod package refer non-mod package. } else { if (!crossdepfound) { crossdepfound = true; sw.WriteLine("Cross mod/dist reference found! See below:"); } sw.Write(asset); sw.Write(" ("); sw.Write(assetkey); sw.Write(") -> "); sw.Write(dep); sw.Write(" ("); sw.Write(depkey); sw.Write(")"); sw.WriteLine(); } } } if (!crossdepfound) { sw.WriteLine("No cross mod/dist reference found."); } // check non build dep sw.WriteLine(); bool nonbuilddepfound = false; foreach (var kvpdep in resdep) { var asset = kvpdep.Key; var deps = kvpdep.Value; foreach (var dep in deps) { if (!asset2reskey.ContainsKey(dep) && !nodepassets.Contains(dep)) { if (dep.StartsWith("Assets/") || dep.StartsWith("Packages/") && !string.IsNullOrEmpty(CapsModEditor.GetAssetModName(dep))) { if (!nonbuilddepfound) { nonbuilddepfound = true; sw.WriteLine("Non build dependency found! See below:"); } sw.Write(asset); sw.Write(" -> "); sw.Write(dep); sw.WriteLine(); } } } } if (!nonbuilddepfound) { sw.WriteLine("No non build dependency found."); } } EditorUtility.OpenWithDefaultApp(output); }
public static void GenerateLuaPackFile(int paramCnt) { if (paramCnt <= 0) { return; } //if (GetLuaPackType(paramCnt) != null) //{ // return; //} //string codefolder = "Assets/Mods/" + CapsEditorUtils.__MOD__ + "/LuaHotFix/"; //string file = codefolder + "LuaPack" + paramCnt + ".cs"; string file = "EditorOutput/LuaHotFix/LuaPack/" + "LuaPack" + paramCnt + ".cs"; var sb = new System.Text.StringBuilder(); sb.Clear(); for (int i = 0; i < paramCnt; ++i) { if (i > 0) { sb.Append(", "); } sb.Append("T"); sb.Append(i); } string gargs = sb.ToString(); sb.Clear(); for (int i = 0; i < paramCnt; ++i) { if (i > 0) { sb.Append(", "); } sb.Append("T"); sb.Append(i); sb.Append(" p"); sb.Append(i); } string pargs = sb.ToString(); using (var sw = PlatDependant.OpenWriteText(file)) { sw.WriteLine("using System;"); sw.WriteLine("using System.Collections.Generic;"); sw.WriteLine("using Capstones.LuaLib;"); sw.WriteLine(); sw.WriteLine("namespace Capstones.LuaWrap"); sw.WriteLine("{"); sw.Write(" public struct LuaPack<"); sw.Write(gargs); sw.WriteLine("> : ILuaPack"); sw.WriteLine(" {"); for (int i = 0; i < paramCnt; ++i) { sw.Write(" public T"); sw.Write(i); sw.Write(" t"); sw.Write(i); sw.WriteLine(";"); } sw.Write(" public LuaPack("); sw.Write(pargs); sw.WriteLine(")"); sw.WriteLine(" {"); for (int i = 0; i < paramCnt; ++i) { sw.Write(" t"); sw.Write(i); sw.Write(" = p"); sw.Write(i); sw.WriteLine(";"); } sw.WriteLine(" }"); sw.WriteLine(); sw.Write(" public int ElementCount { get { return "); sw.Write(paramCnt); sw.WriteLine("; } }"); sw.WriteLine(" public void GetFromLua(IntPtr l)"); sw.WriteLine(" {"); for (int i = 0; i < paramCnt; ++i) { sw.Write(" l.GetLua(-"); sw.Write(i + 1); sw.Write(", out t"); sw.Write(paramCnt - i - 1); sw.WriteLine(");"); } sw.WriteLine(" }"); sw.WriteLine(" public void PushToLua(IntPtr l)"); sw.WriteLine(" {"); for (int i = 0; i < paramCnt; ++i) { sw.Write(" l.PushLua(t"); sw.Write(i); sw.WriteLine(");"); } sw.WriteLine(" }"); sw.WriteLine(" public object this[int index]"); sw.WriteLine(" {"); sw.WriteLine(" get { return _IndexAccessors.GetItem(ref this, index); }"); sw.WriteLine(" set { _IndexAccessors.SetItem(ref this, index, value); }"); sw.WriteLine(" }"); sw.Write(" private static LuaPackIndexAccessorList<LuaPack<"); sw.Write(gargs); sw.Write(">> _IndexAccessors = new LuaPackIndexAccessorList<LuaPack<"); sw.Write(gargs); sw.WriteLine(">>"); sw.WriteLine(" {"); for (int i = 0; i < paramCnt; ++i) { sw.Write(" { (ref LuaPack<"); sw.Write(gargs); sw.Write("> thiz) => thiz.t"); sw.Write(i); sw.Write(", (ref LuaPack<"); sw.Write(gargs); sw.Write("> thiz, object val) => thiz.t"); sw.Write(i); sw.Write(" = (T"); sw.Write(i); sw.WriteLine(")val },"); } sw.WriteLine(" };"); sw.Write(" public void Deconstruct("); for (int i = 0; i < paramCnt; ++i) { if (i > 0) { sw.Write(", "); } sw.Write("out T"); sw.Write(i); sw.Write(" o"); sw.Write(i); } sw.WriteLine(")"); sw.WriteLine(" {"); for (int i = 0; i < paramCnt; ++i) { sw.Write(" o"); sw.Write(i); sw.Write(" = t"); sw.Write(i); sw.WriteLine(";"); } sw.WriteLine(" }"); sw.WriteLine(); sw.WriteLine("#if !UNITY_ENGINE && !UNITY_5_3_OR_NEWER || NET_4_6 || NET_STANDARD_2_0"); sw.Write(" public static implicit operator LuaPack<"); sw.Write(gargs); sw.Write(">("); if (paramCnt >= 8) { sw.Write("("); sw.Write(gargs); sw.Write(")"); } else { sw.Write("ValueTuple<"); sw.Write(gargs); sw.Write(">"); } sw.WriteLine(" t)"); sw.WriteLine(" {"); sw.Write(" return new LuaPack<"); sw.Write(gargs); sw.Write(">("); for (int i = 0; i < paramCnt; ++i) { if (i > 0) { sw.Write(", "); } sw.Write("t.Item"); sw.Write(i + 1); } sw.WriteLine(");"); sw.WriteLine(" }"); sw.Write(" public static implicit operator "); if (paramCnt >= 8) { sw.Write("("); sw.Write(gargs); sw.Write(")"); } else { sw.Write("ValueTuple<"); sw.Write(gargs); sw.Write(">"); } sw.Write("(LuaPack<"); sw.Write(gargs); sw.WriteLine("> p)"); sw.WriteLine(" {"); sw.Write(" return "); if (paramCnt < 8) { sw.Write("new ValueTuple<"); sw.Write(gargs); sw.Write(">"); } sw.Write("("); for (int i = 0; i < paramCnt; ++i) { if (i > 0) { sw.Write(", "); } sw.Write("p.t"); sw.Write(i); } sw.WriteLine(");"); sw.WriteLine(" }"); sw.WriteLine("#endif"); sw.WriteLine(" }"); sw.WriteLine("}"); if (paramCnt > 0) { sb.Clear(); for (int i = 0; i < paramCnt; ++i) { sb.Append(", "); sb.Append("out T"); sb.Append(i); sb.Append(" rv"); sb.Append(i); } var outpars = sb.ToString(); sb.Clear(); for (int i = 0; i < paramCnt; ++i) { if (i > 0) { sb.Append(", "); } sb.Append("out rv"); sb.Append(i); } var outset = sb.ToString(); sw.WriteLine("namespace Capstones.LuaWrap"); sw.WriteLine("{"); sw.WriteLine(" public static partial class LuaFuncExHelper"); sw.WriteLine(" {"); sw.Write(" public static void PushArgsAndCall<TIn, "); sw.Write(gargs); sw.Write(">(this IntPtr l"); sw.Write(outpars); sw.Write(", TIn args)"); sw.WriteLine(); sw.WriteLine(" where TIn : struct, ILuaPack"); sw.WriteLine(" {"); sw.Write(" LuaPack<"); sw.Write(gargs); sw.Write("> pack;"); sw.WriteLine(); sw.WriteLine(" PushArgsAndCall(l, args, out pack);"); sw.Write(" pack.Deconstruct("); sw.Write(outset); sw.Write(");"); sw.WriteLine(); sw.WriteLine(" }"); sw.Write(" public static void CallGlobal<TIn, "); sw.Write(gargs); sw.Write(">(this IntPtr l"); sw.Write(outpars); sw.Write(", string name, TIn args)"); sw.WriteLine(); sw.WriteLine(" where TIn : struct, ILuaPack"); sw.WriteLine(" {"); sw.Write(" LuaPack<"); sw.Write(gargs); sw.Write("> pack;"); sw.WriteLine(); sw.WriteLine(" CallGlobal(l, name, args, out pack);"); sw.Write(" pack.Deconstruct("); sw.Write(outset); sw.Write(");"); sw.WriteLine(); sw.WriteLine(" }"); sw.Write(" public static void CallGlobalHierarchical<TIn, "); sw.Write(gargs); sw.Write(">(this IntPtr l"); sw.Write(outpars); sw.Write(", string name, TIn args)"); sw.WriteLine(); sw.WriteLine(" where TIn : struct, ILuaPack"); sw.WriteLine(" {"); sw.Write(" LuaPack<"); sw.Write(gargs); sw.Write("> pack;"); sw.WriteLine(); sw.WriteLine(" CallGlobalHierarchical(l, name, args, out pack);"); sw.Write(" pack.Deconstruct("); sw.Write(outset); sw.Write(");"); sw.WriteLine(); sw.WriteLine(" }"); sw.Write(" public static void DoString<"); sw.Write(gargs); sw.Write(">(this IntPtr l"); sw.Write(outpars); sw.Write(", string chunk)"); sw.WriteLine(); sw.WriteLine(" {"); sw.Write(" LuaPack<"); sw.Write(gargs); sw.Write("> pack;"); sw.WriteLine(); sw.WriteLine(" DoString(l, chunk, out pack);"); sw.Write(" pack.Deconstruct("); sw.Write(outset); sw.Write(");"); sw.WriteLine(); sw.WriteLine(" }"); sw.Write(" public static void DoFile<"); sw.Write(gargs); sw.Write(">(this IntPtr l"); sw.Write(outpars); sw.Write(", string path)"); sw.WriteLine(); sw.WriteLine(" {"); sw.Write(" LuaPack<"); sw.Write(gargs); sw.Write("> pack;"); sw.WriteLine(); sw.WriteLine(" DoFile(l, path, out pack);"); sw.Write(" pack.Deconstruct("); sw.Write(outset); sw.Write(");"); sw.WriteLine(); sw.WriteLine(" }"); sw.Write(" public static void GetTable<"); sw.Write(gargs); sw.Write(">(this IntPtr l"); sw.Write(outpars); sw.Write(", int index, params string[] fields)"); sw.WriteLine(); sw.WriteLine(" {"); sw.Write(" LuaPack<"); sw.Write(gargs); sw.Write("> pack;"); sw.WriteLine(); sw.WriteLine(" GetTable(l, index, out pack, fields);"); sw.Write(" pack.Deconstruct("); sw.Write(outset); sw.Write(");"); sw.WriteLine(); sw.WriteLine(" }"); sw.Write(" public static void GetSubTable<"); sw.Write(gargs); sw.Write(">(this IntPtr l"); sw.Write(outpars); sw.Write(", int index, string fieldname, params string[] fields)"); sw.WriteLine(); sw.WriteLine(" {"); sw.Write(" LuaPack<"); sw.Write(gargs); sw.Write("> pack;"); sw.WriteLine(); sw.WriteLine(" GetTable(l, index, fieldname, out pack, fields);"); sw.Write(" pack.Deconstruct("); sw.Write(outset); sw.Write(");"); sw.WriteLine(); sw.WriteLine(" }"); sw.Write(" public static void GetTableHierarchical<"); sw.Write(gargs); sw.Write(">(this IntPtr l"); sw.Write(outpars); sw.Write(", int index, string fieldname, params string[] fields)"); sw.WriteLine(); sw.WriteLine(" {"); sw.Write(" LuaPack<"); sw.Write(gargs); sw.Write("> pack;"); sw.WriteLine(); sw.WriteLine(" GetTableHierarchical(l, index, fieldname, out pack, fields);"); sw.Write(" pack.Deconstruct("); sw.Write(outset); sw.Write(");"); sw.WriteLine(); sw.WriteLine(" }"); sw.Write(" public static void GetGlobalTable<"); sw.Write(gargs); sw.Write(">(this IntPtr l"); sw.Write(outpars); sw.Write(", string name, params string[] fields)"); sw.WriteLine(); sw.WriteLine(" {"); sw.Write(" LuaPack<"); sw.Write(gargs); sw.Write("> pack;"); sw.WriteLine(); sw.WriteLine(" GetGlobalTable(l, name, out pack, fields);"); sw.Write(" pack.Deconstruct("); sw.Write(outset); sw.Write(");"); sw.WriteLine(); sw.WriteLine(" }"); sw.Write(" public static void GetGlobalTableHierarchical<"); sw.Write(gargs); sw.Write(">(this IntPtr l"); sw.Write(outpars); sw.Write(", string name, params string[] fields)"); sw.WriteLine(); sw.WriteLine(" {"); sw.Write(" LuaPack<"); sw.Write(gargs); sw.Write("> pack;"); sw.WriteLine(); sw.WriteLine(" GetGlobalTableHierarchical(l, name, out pack, fields);"); sw.Write(" pack.Deconstruct("); sw.Write(outset); sw.Write(");"); sw.WriteLine(); sw.WriteLine(" }"); sw.Write(" public static void Require<"); sw.Write(gargs); sw.Write(">(this IntPtr l"); sw.Write(outpars); sw.Write(", string name, params string[] fields)"); sw.WriteLine(); sw.WriteLine(" {"); sw.Write(" LuaPack<"); sw.Write(gargs); sw.Write("> pack;"); sw.WriteLine(); sw.WriteLine(" Require(l, name, out pack, fields);"); sw.Write(" pack.Deconstruct("); sw.Write(outset); sw.Write(");"); sw.WriteLine(); sw.WriteLine(" }"); sw.Write(" public static void Call<TIn, "); sw.Write(gargs); sw.Write(">(this IntPtr l, int index, string func"); sw.Write(outpars); sw.Write(", TIn args)"); sw.WriteLine(); sw.WriteLine(" where TIn : struct, ILuaPack"); sw.WriteLine(" {"); sw.Write(" LuaPack<"); sw.Write(gargs); sw.Write("> pack;"); sw.WriteLine(); sw.WriteLine(" if (func == null)"); sw.WriteLine(" {"); sw.WriteLine(" l.pushvalue(index);"); sw.WriteLine(" }"); sw.WriteLine(" else"); sw.WriteLine(" {"); sw.WriteLine(" l.GetField(index, func);"); sw.WriteLine(" }"); sw.WriteLine(" PushArgsAndCall(l, args, out pack);"); sw.Write(" pack.Deconstruct("); sw.Write(outset); sw.Write(");"); sw.WriteLine(); sw.WriteLine(" }"); sw.WriteLine(" }"); sw.WriteLine("}"); } if (paramCnt > 1) { sw.WriteLine("#if !UNITY_ENGINE && !UNITY_5_3_OR_NEWER || NET_4_6 || NET_STANDARD_2_0"); sw.WriteLine("namespace Capstones.LuaWrap"); sw.WriteLine("{"); sw.WriteLine(" public partial struct LuaPack"); sw.WriteLine(" {"); sw.Write(" public static LuaPack<"); sw.Write(gargs); sw.Write("> Pack<"); sw.Write(gargs); sw.Write(">("); sw.Write(pargs); sw.Write(")"); sw.WriteLine(); sw.WriteLine(" {"); sw.Write(" return new LuaPack<"); sw.Write(gargs); sw.Write(">("); for (int i = 0; i < paramCnt; ++i) { if (i > 0) { sw.Write(", "); } sw.Write("p"); sw.Write(i); } sw.Write(");"); sw.WriteLine(); sw.WriteLine(" }"); sw.Write(" public static LuaPack<"); sw.Write(gargs); sw.Write("> Pack<"); sw.Write(gargs); sw.Write(">(("); sw.Write(gargs); sw.Write(") t)"); sw.WriteLine(); sw.WriteLine(" {"); sw.WriteLine(" return t;"); sw.WriteLine(" }"); sw.Write(" public static ("); sw.Write(gargs); sw.Write(") Unpack<"); sw.Write(gargs); sw.Write(">(LuaPack<"); sw.Write(gargs); sw.Write("> p)"); sw.WriteLine(); sw.WriteLine(" {"); sw.WriteLine(" return p;"); sw.WriteLine(" }"); sw.WriteLine(" }"); sw.WriteLine("}"); sw.WriteLine("#endif"); } } //AssetDatabase.Refresh(); //var comp = new UnityEditor.Compilation.AssemblyBuilder("EditorOutput/Temp.dll", file); //comp.additionalReferences = new[] { "Library/ScriptAssemblies/CapsLua.dll" }; //comp.buildStarted += assemblyPath => //{ // Debug.LogFormat("Assembly build started for {0}", assemblyPath); //}; //// Called on main thread //comp.buildFinished += (assemblyPath, compilerMessages) => //{ // foreach (var message in compilerMessages) // { // if (message.type == UnityEditor.Compilation.CompilerMessageType.Error) // { // Debug.LogError(message.message); // } // else if (message.type == UnityEditor.Compilation.CompilerMessageType.Warning) // { // Debug.LogWarning(message.message); // } // } // var errorCount = compilerMessages.Count(m => m.type == UnityEditor.Compilation.CompilerMessageType.Error); // var warningCount = compilerMessages.Count(m => m.type == UnityEditor.Compilation.CompilerMessageType.Warning); // Debug.LogFormat("Assembly build finished for {0}", assemblyPath); // Debug.LogFormat("Warnings: {0} - Errors: {0}", errorCount, warningCount); // if (errorCount == 0) // { // } //}; //comp.Build(); //new Microsoft.CSharp.CSharpCodeProvider().CompileAssemblyFromFile() }