Exemplo n.º 1
0
        private void SerializeImpl(LuaWriter luaWriter, object o)
        {
            // If object is null, serialize as literal (to 'nil')
            if (o == null)
            {
                this.SerializeLiteral(luaWriter, o);
            }
            else
            {
                // Get the type of the object
                Type type = o.GetType();

                if (type.SerializeAsEnumerable())
                {
                    this.SerializeEnumerable(luaWriter, (IEnumerable)o);
                }
                if (type.SerializeAsDictionary())
                {
                    this.SerializeDictionary(luaWriter, o);
                }
                if (type.SerializeAsLiteral())
                {
                    this.SerializeLiteral(luaWriter, o);
                }
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var rawFeeds = new[]
            {
                FeedReader.Read("http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml")
            };

            var feeds = rawFeeds.Select(feed => new
            {
                feed.Title,
                Items = feed.Items.Select(item => new
                {
                    item.Title,
                    item.Content
                }).ToArray()
            }).ToArray();

            using (var luaWriter = LuaWriter.Create("SavedVariables.lua", new LuaWriterSettings {
                Indent = true
            }))
            {
                var luaSerializer = new LuaSerializer();

                luaWriter.WriteStartAssignment("FEED_READER_FEEDS");
                luaSerializer.Serialize(luaWriter, feeds);
                luaWriter.WriteEndAssignment();
            }
        }
Exemplo n.º 3
0
        public void SetUp()
        {
            stringBuilder = new StringBuilder();
            luaWriter     = LuaWriter.Create(stringBuilder);

            luaSerializer = new LuaSerializer();
        }
Exemplo n.º 4
0
 /// <summary>
 /// Find the proxy for a Writer
 /// </summary>
 public static LuaWriterProxy FindProxy(LuaWriter writer)
 {
     if (writer == null)
     {
         return(null);
     }
     return(_Proxies.FirstOrDefault(p => p.ManagedWriter == writer));
 }
Exemplo n.º 5
0
        public static IntPtr ToFunctionPointer(this LuaWriter d)
        {
            if (d == null)
            {
                return(IntPtr.Zero);
            }

            return(Marshal.GetFunctionPointerForDelegate <LuaWriter>(d));
        }
Exemplo n.º 6
0
        public void Serialize(LuaWriter luaWriter, object o)
        {
            if (luaWriter == null)
            {
                throw new ArgumentNullException("luaWriter");
            }

            this.SerializeImpl(luaWriter, o);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Convert a writer to lua writer
        /// </summary>
        public static Lua.lua_Writer ToLuaWriter(this LuaWriter writer)
        {
            if (writer == null)
            {
                return(null);
            }
            var proxy = LuaWriterProxy.GetProxy(writer);

            return(proxy != null ? proxy.UnmanagedWriter : null);
        }
Exemplo n.º 8
0
        public string WriteLuaString()
        {
            string luaString = string.Empty;

            luaString += LuaWriter.writeDecimalAttribute("previous_dkp", 0);
            luaString += LuaWriter.writeTextAttribute(nameof(Player), Player);
            luaString += LuaWriter.writeTextAttribute(nameof(Class), Class);
            luaString += LuaWriter.writeDecimalAttribute(nameof(Dkp), Dkp);
            luaString += LuaWriter.writeDecimalAttribute(nameof(LifetimeGained), LifetimeGained);
            luaString += LuaWriter.writeDecimalAttribute(nameof(LifetimeSpent), LifetimeSpent);
            return(luaString);
        }
Exemplo n.º 9
0
        public static IntPtr ToFunctionPointer(this LuaWriter d)
        {
            if (d == null)
            {
                return(IntPtr.Zero);
            }

#if NETFRAMEWORK
            return(Marshal.GetFunctionPointerForDelegate(d));
#else
            return(Marshal.GetFunctionPointerForDelegate <LuaWriter>(d));
#endif
        }
Exemplo n.º 10
0
        private void SerializeEnumerable(LuaWriter luaWriter, IEnumerable collection)
        {
            luaWriter.WriteStartTable();

            foreach (var item in collection)
            {
                luaWriter.WriteStartTableField();
                this.SerializeImpl(luaWriter, item);
                luaWriter.WriteEndTableField();
            }

            luaWriter.WriteEndTable();
        }
Exemplo n.º 11
0
 /// <summary>
 /// Find or create a proxy for a writer
 /// </summary>
 public static LuaWriterProxy GetProxy(LuaWriter writer)
 {
     if (writer == null) return null;
     var result = FindProxy(writer);
     if (result == null)
     {
         result = new LuaWriterProxy() {
             ManagedWriter = writer
         };
         result.UnmanagedWriter = result.InvokeManagementWriter;
         _Proxies.Add(result);
     }
     return result;
 }
Exemplo n.º 12
0
        public static DumpStatus Dump(
            LuaProto proto, LuaWriter writer, bool strip)
        {
            var d = new DumpState();

            d.Writer = writer;
            d.Strip  = strip;
            d.Status = DumpStatus.OK;

            d.DumpHeader();
            d.DumpFunction(proto);

            return(d.Status);
        }
Exemplo n.º 13
0
        private void SerializeDictionary(LuaWriter luaWriter, object o)
        {
            Type type = o.GetType();

            luaWriter.WriteStartTable();

            foreach (var propertyInfo in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                luaWriter.WriteStartTableField(propertyInfo.Name, false);
                this.SerializeImpl(luaWriter, propertyInfo.GetValue(o, null));
                luaWriter.WriteEndTableField();
            }

            luaWriter.WriteEndTable();
        }
Exemplo n.º 14
0
        public void SaveFeeds()
        {
            Feed[] feeds = this.GetTopLevelFeeds();
            if (feeds != null)
            {
                using (var luaWriter = LuaWriter.Create(savedVariablesPath))
                {
                    var luaSerializer = new LuaSerializer();

                    luaWriter.WriteStartAssignment(feedsVariableName);
                    luaSerializer.Serialize(luaWriter, feeds);
                    luaWriter.WriteEndAssignment();
                }
            }
        }
Exemplo n.º 15
0
        private static int Str_Dump(ILuaState lua)
        {
            lua.L_CheckType(1, LuaType.LUA_TFUNCTION);
            lua.SetTop(1);
            var       bsb       = new ByteStringBuilder();
            LuaWriter writeFunc =
                delegate(byte[] bytes, int start, int length)
            {
                bsb.Append(bytes, start, length);
                return(DumpStatus.OK);
            };

            if (lua.Dump(writeFunc) != DumpStatus.OK)
            {
                return(lua.L_Error("unable to dump given function"));
            }
            lua.PushString(bsb.ToString());
            return(1);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Find or create a proxy for a writer
        /// </summary>
        public static LuaWriterProxy GetProxy(LuaWriter writer)
        {
            if (writer == null)
            {
                return(null);
            }
            var result = FindProxy(writer);

            if (result == null)
            {
                result = new LuaWriterProxy()
                {
                    ManagedWriter = writer
                };
                result.UnmanagedWriter = result.InvokeManagementWriter;
                _Proxies.Add(result);
            }
            return(result);
        }
Exemplo n.º 17
0
        DumpStatus ILuaAPI.Dump(LuaWriter writeFunc)
        {
            Utl.ApiCheckNumElems(this, 1);

            var below = Stack[Top.Index - 1];

            if (!below.V.TtIsFunction() || !below.V.ClIsLuaClosure())
            {
                return(DumpStatus.ERROR);
            }

            var o = below.V.ClLValue();

            if (o == null)
            {
                return(DumpStatus.ERROR);
            }

            return(DumpState.Dump(o.Proto, writeFunc, false));
        }
Exemplo n.º 18
0
        public MuteSoundsUI()
        {
            InitializeComponent();
            this.CSVParser       = new SoundKitEntryParser(this);
            this.TSFParser       = new TargetSoundFileParser(this);
            this.LWriter         = new LuaWriter(this);
            this.ECollector      = new ErrorCollector(this);
            this.Default_Font    = TextBoxLog.Font;
            this.Bold_Font       = new Font(Default_Font, FontStyle.Bold);
            this.MaximizeBox     = false;
            this.MinimizeBox     = false;
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            versionLabel.Text    = "v" + VersionNum + " - " + VersionDate;

            this.Folder_Output            = Directory.GetCurrentDirectory() + "\\Output\\";
            this.Folder_SoundDataLocation = Directory.GetCurrentDirectory() + "\\SoundKitData\\";
            this.Folder_SoundTargetFolder = Directory.GetCurrentDirectory() + "\\SoundTargets\\";
            if (!Directory.Exists(Folder_Output))
            {
                Directory.CreateDirectory(Folder_Output);
            }

            if (!Directory.Exists(Folder_SoundDataLocation) || !File.Exists(Folder_SoundDataLocation + "soundkitentry.csv"))
            {
                startError = true;
                LogMessage("Couldn't find 'soundkitentry.csv' at location: \n'" + Folder_SoundDataLocation + "'\n", eColor, Bold_Font);
                RunButton.Enabled = false;
            }

            if (!Directory.Exists(Folder_SoundTargetFolder))
            {
                startError = true;
                LogMessage("Couldn't find directory: \n'" + Folder_SoundTargetFolder + "'\n", eColor, Bold_Font);
                RunButton.Enabled = false;
            }

            if (!startError)
            {
                LogMessage("Ready!", Color.Black, Bold_Font);
            }
        }
Exemplo n.º 19
0
 public static void DumpingToFile(LuaProto proto, string filename, bool strip)
 {
     using (var writer = new BinaryWriter(File.Open(
                                              filename, FileMode.Create)))
     {
         LuaWriter writeFunc =
             delegate(byte[] bytes, int start, int length)
         {
             try
             {
                 writer.Write(bytes, start, length);
                 return(DumpStatus.OK);
             }
             catch (Exception)
             {
                 return(DumpStatus.ERROR);
             }
         };
         DumpState.Dump(proto, writeFunc, strip);
     }
 }
Exemplo n.º 20
0
            internal string CreateParamListString()
            {
                if (usedPar.Count == 0)
                {
                    return(usedIt ? $"({LuaWriter.GetLambdaImplicitIterName()})" : "()");
                }
                int           num  = usedPar.Max();
                StringBuilder sb   = new("(");
                var           pars = Enumerable.Range(1, num).Select(index => usedPar.Contains(index) ? LuaWriter.GetLambdaImplicitParamName(index) : "_").ToArray();

                if (pars.Length > 0)
                {
                    sb.Append(pars[0]);
                    foreach (var par in pars.Skip(1))
                    {
                        sb.Append(", ");
                        sb.Append(par);
                    }
                }
                sb.Append(")");
                return(sb.ToString());
            }
Exemplo n.º 21
0
 public static void WriteAnimClipData()
 {
     LuaWriter.Write <AnimClipData.AnimClipData>();
     Shell.Run("CopyAnimClipFile");
 }
Exemplo n.º 22
0
        DumpStatus ILuaAPI.Dump( LuaWriter writeFunc )
        {
            Utl.ApiCheckNumElems( this, 1 );

            var below = Stack[Top.Index-1];
            if(!below.V.TtIsFunction() || !below.V.ClIsLuaClosure())
                return DumpStatus.ERROR;

            var o = below.V.ClLValue();
            if(o == null)
                return DumpStatus.ERROR;

            return DumpState.Dump(o.Proto, writeFunc, false);
        }
Exemplo n.º 23
0
		internal static extern int lua_dump(LuaStatePtr l, LuaWriter writer, IntPtr data);
Exemplo n.º 24
0
 internal static extern int lua_dump(LuaStatePtr l, LuaWriter writer, IntPtr data);
Exemplo n.º 25
0
        private static void Main(string[] args)
        {
            string inPath  = "";
            string outPath = "";

            if (args.Length < 2)
            {
                Console.Write("usage:\n\t Convert.exe [excel_输入目录] [lua_输出目录]\n输入后按 Enter 继续:\n");
                string s = Console.ReadLine();
                inPath  = s.Split(' ')[0];
                outPath = s.Split(' ')[1];
            }
            else
            {
                inPath  = args[0];
                outPath = args[1];
            }

            if (inPath != null && inPath != "")
            {
                if (outPath == null || outPath == "")
                {
                    outPath = "out";
                }

                long lastWriteTime = 0;
                long newWriteTime  = 0;

                var outDir = new DirectoryInfo(outPath);
                if (!outDir.Exists)
                {
                    outDir.Create();
                }

                if (new FileInfo(inPath + @"\lastWriteTime").Exists&& args.Length == 2)
                {
                    StreamReader reader = new StreamReader(inPath + @"\lastWriteTime");
                    if (reader != null)
                    {
                        string s = reader.ReadLine();
                        reader.Close();
                        //lastWriteTime = DateTime.ParseExact(s, "yyyy_MM_dd-HH_mm_ss", CultureInfo.InvariantCulture);
                        if (!long.TryParse(s, out lastWriteTime))
                        {
                            lastWriteTime = 0;
                        }
                        newWriteTime = lastWriteTime;
                    }
                }
                Console.WriteLine("上次转换时间:" + DateTime.FromFileTimeUtc(lastWriteTime));

                DirectoryInfo info  = new DirectoryInfo(inPath);
                int           errno = 0;
                foreach (FileInfo info2 in info.GetFiles("*.xls"))
                {
                    char[] separator = new char[] { '.' };
                    if (info2.LastWriteTime.ToFileTimeUtc() <= lastWriteTime)
                    {
                        Console.WriteLine(info2.LastWriteTime.ToString("yyyy_MM_dd-HH_mm_ss") + " 无需更新【" + info2.Name + "】");
                    }
                    else
                    {
                        if (info2.LastWriteTime.ToFileTimeUtc() > newWriteTime)
                        {
                            newWriteTime = info2.LastWriteTime.ToFileTimeUtc();
                        }
                        Console.WriteLine(info2.LastWriteTime.ToString("yyyy_MM_dd-HH_mm_ss") + " 开始转换【" + info2.Name + "】... ");

                        try
                        {
                            //Provider=Microsoft.Jet.OLEDB.4.0;这个是指办公软件
                            //Data Source=" + filepath + ";这是excel位置
                            //Extended Properties='Excel 8.0;IMEX=1'";这个是Excel的版本
                            //[Sheet1$]指的是Excel表中第一个工作薄

                            //string strConn = "Provider=Microsoft.Jet.OleDb.4.0;"
                            //    + "data source=" + info2.FullName
                            //    + ";Extended Properties='Excel 8.0; HDR=YES; IMEX=1'";
                            string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;"
                                             + "Data Source=" + info2.FullName
                                             + ";Extended Properties='Excel 12.0;HDR=Yes;IMEX=1;'";
                            OleDbConnection conn = new OleDbConnection(strConn);
                            conn.Open();

                            DataTable tables = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                            for (int i = 0; i < 1 /*tables.Rows.Count*/; i += 2)
                            {
                                DataRow drow      = tables.Rows[i];
                                string  sheetname = drow["TABLE_NAME"].ToString();
                                Console.Write("  " + sheetname);

                                DataTable        ds     = new DataTable();
                                string           strcom = "select * from [" + sheetname + "]";
                                OleDbDataAdapter odda   = new OleDbDataAdapter(strcom, conn);
                                odda.Fill(ds);

                                if (LuaWriter.writeLua(sheetname.Replace("$", ""), ds, outPath))
                                {
                                    Console.Write(" 成功\n");
                                }
                                else
                                {
                                    Console.Write(" 失败!!!!!!!!!\n");
                                    ++errno;
                                }
                            }
                            conn.Close();
                        }
                        catch (OleDbException e)
                        {
                            Console.Error.Write("错误信息:" + e.Message);
                        }
                    }
                } // for

                if (newWriteTime > lastWriteTime)
                {
                    StreamWriter writer = new StreamWriter(inPath + @"\lastWriteTime", false);
                    writer.Write(
                        newWriteTime
                        );
                    writer.Close();
                }

                if (errno > 0)
                {
                    Console.WriteLine("转表 {0} 个错误,按 Enter 退出", errno);
                    Console.ReadLine();
                }
                else
                {
                    System.Threading.Thread.Sleep(1000);
                }
            }
        }
Exemplo n.º 26
0
 public static int Dump(LuaStatePtr l, LuaWriter writer, IntPtr data)
 {
     return(LuaDelegates.lua_dump(l, writer, data));
 }
Exemplo n.º 27
0
        static void RunOptions(Options options)
        {
            if (!Directory.Exists(options.InputDir))
            {
                return;
            }

            LogHandler logHandler = new LogHandler((type, id, msg) =>
            {
                string msgType = "Info";
                Color color    = Color.White;

                if (type == LogType.Error)
                {
                    msgType = "Error";
                    color   = Color.Red;
                }
                else if (type == LogType.Warning)
                {
                    msgType = "Warning";
                    color   = Color.Yellow;
                }

                Colorful.Console.WriteLine($"[{msgType}]    [{id}]  {msg}", color);
            });

            WorkbookReader reader = new WorkbookReader(logHandler);

            TypeContext context = new TypeContext();

            context.Add(typeof(LogHandler), logHandler);

            Workbook[] workbooks = reader.ReadExcelFromDir(options.InputDir);
            if (workbooks != null && workbooks.Length > 0)
            {
                foreach (var workbook in workbooks)
                {
                    string dir = $"{options.OutputDir}/{workbook.Name}";
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    bool result = workbook.Verify(context);
                    if (result)
                    {
                        for (int i = 0; i < workbook.SheetCount; ++i)
                        {
                            Sheet sheet = workbook.GetSheeetByIndex(i);
                            if (options.Format == OutputFormat.Json)
                            {
                                JsonWriter.WriteTo(sheet, dir);
                            }
                            else if (options.Format == OutputFormat.Ndb)
                            {
                                NdbWriter.WriteTo(sheet, dir);
                            }
                            else if (options.Format == OutputFormat.Lua)
                            {
                                LuaWriter.WriteTo(sheet, dir);
                            }
                        }
                    }
                }
            }
            context.Clear();
        }
Exemplo n.º 28
0
 /// <summary>
 /// Dumps a function as a binary chunk.
 /// </summary>
 public int Dump(LuaWriter writer, Object data, int strip)
 {
     return Lua.lua_dump(NativeState, writer.ToLuaWriter(), UserDataRef.GetRef(data), strip);
 }
Exemplo n.º 29
0
 private void SerializeLiteral(LuaWriter luaWriter, object value)
 {
     luaWriter.WriteLiteralExpression(value);
 }
Exemplo n.º 30
0
 public static extern int Dump(IntPtr State, LuaWriter Writer, IntPtr P);
Exemplo n.º 31
0
 /// <summary>
 /// Find the proxy for a Writer
 /// </summary>
 public static LuaWriterProxy FindProxy(LuaWriter writer)
 {
     if (writer == null) return null;
     return _Proxies.FirstOrDefault(p => p.ManagedWriter == writer);
 }
Exemplo n.º 32
0
        public static void startConvert(string cilckName, bool isClientNeed, bool isServerNeed, int number)
        {
            var outDir = new DirectoryInfo(ConfigObjects.directories.客户端表输出路径);

            if (!outDir.Exists)
            {
                outDir.Create();
            }
            Log.info("客户端输出目录:" + outDir.FullName);

            outDir = new DirectoryInfo(ConfigObjects.directories.务器表输出路径);
            if (!outDir.Exists)
            {
                outDir.Create();
            }
            Log.info("服务器输出目录:" + outDir.FullName);

            // 开始转换
            foreach (FileInfo info in m_lstTableInfo)
            {
                if (cilckName != "" && cilckName == info.Name)
                {
                    string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;"
                                     + "Data Source=" + info.FullName
                                     + ";Extended Properties='Excel 12.0;HDR=Yes;IMEX=1;'";
                    OleDbConnection conn = new OleDbConnection(strConn);
                    conn.Open();

                    DataTable tables = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                    for (int i = 0; i < 1 /*tables.Rows.Count*/; i += 2)
                    {
                        DataRow drow      = tables.Rows[i];
                        string  sheetname = drow["TABLE_NAME"].ToString();
                        Log.info("开始转换表【" + sheetname + "】...");

                        DataTable        ds     = new DataTable();
                        string           strcom = "select * from [" + sheetname + "]";
                        OleDbDataAdapter odda   = new OleDbDataAdapter(strcom, conn);
                        odda.Fill(ds);

                        // 输出客户端
                        if (isClientNeed)
                        {
                            if (LuaWriter.writeLua(sheetname.Replace("$", ""), ds, ConfigObjects.directories.客户端表输出路径))
                            {
                            }
                            else
                            {
                                Log.info("【" + sheetname + "】表转换失败");
                            }
                        }

                        // 输出服务器
                        if (isServerNeed)
                        {
                            if (JsonWriter.writeJson(sheetname.Replace("$", ""), ds, ConfigObjects.directories.务器表输出路径))
                            {
                            }
                            else
                            {
                                Log.info("【" + sheetname + "】表转换失败");
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 33
0
 DumpStatus ILuaAPI.Dump( LuaWriter writeFunc )
 {
     Utl.ApiCheckNumElems( this, 1 );
     var o = (Top-1).Value as LuaLClosure;
     var status = (o == null) ? DumpStatus.ERROR :
         DumpState.Dump( o.Proto, writeFunc, false );
     return status;
 }