static void Main(string[] args) { UserData.RegisterAssembly(typeof(FreelancerGame).Assembly); foreach (var t in typeof(FreelancerGame).Assembly.GetTypes()) { if (t.GetCustomAttribute <LibreLancer.Interface.UiLoadableAttribute>() != null) { UserData.RegisterType(t); } } UserData.RegisterType <LibreLancer.Interface.LuaCompatibleDictionary <string, bool> >(); HardwireGeneratorRegistry.RegisterPredefined(); var dump = UserData.GetDescriptionOfRegisteredTypes(true); var hw = new MoonSharp.Hardwire.HardwireGenerator("LibreLancer.Lua", "LuaContext_Hardwire", new Logger(), HardwireCodeGenerationLanguage.CSharp); hw.AllowInternals = true; hw.BuildCodeModel(dump); var src = hw.GenerateSourceCode(); src = src.Replace("public abstract class LuaContext_Hardwire", "abstract class LuaContext_Hardwire"); string path = "LuaContext_Hardwire.cs"; if (args.Length > 0) { path = args[0]; } File.WriteAllText(path, src); }
public static void Generate(string language, string luafile, string destfile, bool allowInternals, string classname, string namespacename) { var logger = new ConsoleLogger(); try { Script s = new Script(CoreModules.None); var eee = s.CreateDynamicExpression(File.ReadAllText(luafile)); Table t = eee.Evaluate(null).Table; HardwireGeneratorRegistry.RegisterPredefined(); HardwireGenerator hcg = new HardwireGenerator(namespacename ?? "HardwiredClasses", classname ?? "HardwireTypes", logger, language == "vb" ? HardwireCodeGenerationLanguage.VB : HardwireCodeGenerationLanguage.CSharp) { AllowInternals = allowInternals }; hcg.BuildCodeModel(t); string code = hcg.GenerateSourceCode(); File.WriteAllText(destfile, code); } catch (Exception ex) { Console.WriteLine("Internal error : {0}", ex.Message); } Console.WriteLine(); Console.WriteLine("done: {0} errors, {1} warnings.", logger.Errors, logger.Warnings); }