当前位置: 首页>>代码示例>>C#>>正文


C# LuaState.ToString方法代码示例

本文整理汇总了C#中LuaState.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# LuaState.ToString方法的具体用法?C# LuaState.ToString怎么用?C# LuaState.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LuaState的用法示例。


在下文中一共展示了LuaState.ToString方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestInsert

        public void TestInsert()
        {
            LuaState L = null;
            using (L = new LuaState())
            {
                Assert.Equal(0, L.GetTop());
                L.PushNumber(1);
                L.PushString("Test");
                L.PushNumber(2);
                L.PushString("Text");
                L.PushNumber(3);
                L.PushString("Toto");
                L.PushNumber(4);
                Assert.Equal(7, L.GetTop());

                L.Insert(2);
                Assert.Equal(7, L.GetTop());

                Assert.Equal(1, L.ToNumber(1));
                Assert.Equal(4, L.ToNumber(2));
                Assert.Equal("Test", L.ToString(3));
                Assert.Equal(2, L.ToNumber(4));
                Assert.Equal("Text", L.ToString(5));
                Assert.Equal(3, L.ToNumber(6));
                Assert.Equal("Toto", L.ToString(7));
            }
        }
开发者ID:ygrenier,项目名称:LuaN,代码行数:27,代码来源:LuaStateTest.cs

示例2: TestXMove

        public void TestXMove()
        {
            LuaState L = null;
            using (L = new LuaState())
            {
                L.PushString("#1 Line 1");
                L.PushString("#1 Line 2");
                L.PushString("#1 Line 3");
                Assert.Equal(3, L.GetTop());

                using (LuaState L2 = new LuaState())
                {
                    L2.PushString("#2 Line 1");
                    L2.PushString("#2 Line 2");
                    L2.PushString("#2 Line 3");
                    Assert.Equal(3, L2.GetTop());

                    Assert.Same(L, L.XMove(L2, 2));

                    Assert.Equal(1, L.GetTop());
                    Assert.Equal(5, L2.GetTop());

                    Assert.Equal("#1 Line 1", L.ToString(1));
                    Assert.Equal(null, L.ToString(2));

                    Assert.Equal("#2 Line 1", L2.ToString(1));
                    Assert.Equal("#2 Line 2", L2.ToString(2));
                    Assert.Equal("#2 Line 3", L2.ToString(3));
                    Assert.Equal("#1 Line 2", L2.ToString(4));
                    Assert.Equal("#1 Line 3", L2.ToString(5));

                }

                Assert.Throws<ArgumentNullException>(() => L.XMove(null, 1));

                var mockLs = new Mock<ILuaState>();
                Assert.Throws<InvalidOperationException>(() => L.XMove(mockLs.Object, 1));

            }
        }
开发者ID:ygrenier,项目名称:LuaN,代码行数:40,代码来源:LuaStateTest.cs

示例3: TestDump

        public void TestDump()
        {
            LuaState L = null;
            using (L = new LuaState())
            {
                String chunk = @"
            a = 'Lua'
            b = ' rocks'
            c=a..b
            return c..'!!'
            ";
                Byte[] chunkBytes = Encoding.ASCII.GetBytes(chunk);
                int curr = 0;
                LuaReader loadChunk = (l, ud) => {
                    Byte[] res = null;
                    if (curr < chunkBytes.Length)
                    {
                        int c = Math.Min(chunkBytes.Length, chunkBytes.Length - curr);
                        res = new Byte[c];
                        Array.Copy(chunkBytes, curr, res, 0, c);
                        curr += c;
                    }
                    return res;
                };
                var st = L.Load(loadChunk, null, "main", null);
                Assert.Equal(LuaStatus.OK, st);

                List<Byte[]> dump = new List<byte[]>();
                var r = L.Dump((l, b, ud) => {
                    dump.Add(b);
                    return 0;
                }, null, 0);
                Assert.Equal(0, r);
                Byte[] dumpBytes = dump.SelectMany(d => d).ToArray();
                Assert.Equal(199, dumpBytes.Length);

                // Remove the function
                L.Pop(1);
                Assert.Equal(0, L.GetTop());

                // Reload chunk compiled
                chunkBytes = dumpBytes;
                curr = 0;
                st = L.Load(loadChunk, null, "main", "b");
                Assert.Equal(LuaStatus.OK, st);
                st = L.PCall(0, 1, 0);
                Assert.Equal(LuaStatus.OK, st);
                Assert.Equal("Lua rocks!!", L.ToString(-1));

            }
        }
开发者ID:ygrenier,项目名称:LuaN,代码行数:51,代码来源:LuaStateTest.cs

示例4: TestConcat

 public void TestConcat()
 {
     LuaState L = null;
     using (L = new LuaState())
     {
         L.PushString("One");
         L.PushNumber(2);
         L.PushString("Three");
         L.PushNumber(4);
         L.Concat(3);
         Assert.Equal("2.0Three4.0", L.ToString(-1));
     }
 }
开发者ID:ygrenier,项目名称:LuaN,代码行数:13,代码来源:LuaStateTest.cs

示例5: TestToString

 public void TestToString()
 {
     LuaState L = null;
     using (L = new LuaState())
     {
         LuaFunction f = l => 0;
         L.PushNil()
             .PushNumber(123.45)
             .PushInteger(987)
             .PushString("Test")
             .PushString("5.6")
             .PushString("5D")
             .PushString("5z")
             .PushBoolean(true)
             .PushCClosure(f, 0)
             //.PushLightUserData(DateTime.Now)
             .PushGlobalTable()
             ;
         L.PushThread();
         Assert.Equal(null, L.ToString(1));
         Assert.Equal("123.45", L.ToString(2));
         Assert.Equal("987", L.ToString(3));
         Assert.Equal("Test", L.ToString(4));
         Assert.Equal("5.6", L.ToString(5));
         Assert.Equal("5D", L.ToString(6));
         Assert.Equal("5z", L.ToString(7));
         Assert.Equal(null, L.ToString(8));
         Assert.Equal(null, L.ToString(9));
         Assert.Equal(null, L.ToString(10));
         Assert.Equal(null, L.ToString(11));
         Assert.Equal(null, L.ToString(12));
     }
 }
开发者ID:ygrenier,项目名称:LuaN,代码行数:33,代码来源:LuaStateTest.cs

示例6: TestRawSetGetP

        public void TestRawSetGetP()
        {
            LuaState L = null;
            using (L = new LuaState())
            {
                L.CreateTable(0, 0);
                Assert.Equal(1, L.GetTop());

                L.PushString("Value");
                L.RawSetP(1, new IntPtr(2));
                Assert.Equal(1, L.GetTop());

                L.RawGetP(1, new IntPtr(1));
                Assert.Equal(2, L.GetTop());
                Assert.Equal(true, L.IsNil(-1));

                L.RawGetP(1, new IntPtr(2));
                Assert.Equal(3, L.GetTop());
                Assert.Equal(true, L.IsString(-1));
                Assert.Equal("Value", L.ToString(-1));
            }
        }
开发者ID:ygrenier,项目名称:LuaN,代码行数:22,代码来源:LuaStateTest.cs

示例7: TestSetGetTable

        public void TestSetGetTable()
        {
            LuaState L = null;
            using (L = new LuaState())
            {
                L.CreateTable(0, 0);
                Assert.Equal(1, L.GetTop());

                L.PushInteger(2).PushString("Value");
                L.SetTable(1);
                Assert.Equal(1, L.GetTop());

                L.PushInteger(1);
                L.GetTable(1);
                Assert.Equal(2, L.GetTop());
                Assert.Equal(true, L.IsNil(-1));

                L.PushInteger(2);
                L.GetTable(1);
                Assert.Equal(3, L.GetTop());
                Assert.Equal(true, L.IsString(-1));
                Assert.Equal("Value", L.ToString(-1));
            }
        }
开发者ID:ygrenier,项目名称:LuaN,代码行数:24,代码来源:LuaStateTest.cs

示例8: TestPushValue

        public void TestPushValue()
        {
            LuaState L = null;
            using (L = new LuaState())
            {
                Assert.Equal(0, L.GetTop());
                L.PushNumber(1);
                L.PushString("Test");
                L.PushNumber(2);
                L.PushString("Text");
                Assert.Equal(4, L.GetTop());

                L.PushValue(-1).PushValue(2);
                Assert.Equal(6, L.GetTop());

                Assert.Equal(1, L.ToNumber(1));
                Assert.Equal("Test", L.ToString(2));
                Assert.Equal(2, L.ToNumber(3));
                Assert.Equal("Text", L.ToString(4));
                Assert.Equal("Text", L.ToString(5));
                Assert.Equal("Test", L.ToString(6));

            }
        }
开发者ID:ygrenier,项目名称:LuaN,代码行数:24,代码来源:LuaStateTest.cs

示例9: TestPushFString

 public void TestPushFString()
 {
     LuaState L = null;
     using (L = new LuaState())
     {
         L.PushFString("-s-d-", 1234);
         L.PushFString("-%s-", "Text");
         L.PushFString("-%f-", 123.45);
         L.PushFString("-%d-", 987);
         L.PushFString("-%s-%s-", "Str", "Text");
         L.PushFString("-%s-%f-", "Str", 123.45);
         L.PushFString("-%s-%d-", "Str", 987);
         L.PushFString("-%f-%s-", 11.22, "Text");
         L.PushFString("-%f-%f-", 11.22, 123.45);
         L.PushFString("-%f-%d-", 11.22, 987);
         L.PushFString("-%d-%s-", 9988, "Text");
         L.PushFString("-%d-%f-", 9988, 123.45);
         L.PushFString("-%d-%d-", 9988, 987);
         Assert.Equal(13, L.GetTop());
         Assert.Equal(LuaType.String, L.Type(-1));
         Assert.Equal("-s-d-", L.ToString(1));
         Assert.Equal("-Text-", L.ToString(2));
         Assert.Equal("-123.45-", L.ToString(3));
         Assert.Equal("-987-", L.ToString(4));
         Assert.Equal("-Str-Text-", L.ToString(5));
         Assert.Equal("-Str-123.45-", L.ToString(6));
         Assert.Equal("-Str-987-", L.ToString(7));
         Assert.Equal("-11.22-Text-", L.ToString(8));
         Assert.Equal("-11.22-123.45-", L.ToString(9));
         Assert.Equal("-11.22-987-", L.ToString(10));
         Assert.Equal("-9988-Text-", L.ToString(11));
         Assert.Equal("-9988-123.45-", L.ToString(12));
         Assert.Equal("-9988-987-", L.ToString(13));
     }
 }
开发者ID:ygrenier,项目名称:LuaN,代码行数:35,代码来源:LuaStateTest.cs

示例10: TestPCall

        public void TestPCall()
        {
            LuaState L = null;
            using (L = new LuaState())
            {
                L.PushFunction(l => {
                    var a = L.ToNumber(1);
                    var b = L.ToNumber(2);
                    L.PushNumber(a * b);
                    return 1;
                });
                L.PushNumber(12);
                L.PushNumber(4);
                Assert.Equal(LuaStatus.OK, L.PCall(2, 1, 0));
                Assert.Equal(1, L.GetTop());
                Assert.Equal(48, L.ToNumber(-1));

                L.DoString(@"
            function testA(a,b)
            return a-b
            end
            function testB(a,b)
            DoAnError(a,b)
            end
            ");
                Assert.Equal(1, L.GetTop());
                L.GetGlobal("testA");
                L.PushNumber(12);
                L.PushNumber(4);
                Assert.Equal(LuaStatus.OK, L.PCall(2, 1, 0));
                Assert.Equal(2, L.GetTop());
                Assert.Equal(8, L.ToNumber(-1));

                L.GetGlobal("testB");
                L.PushNumber(12);
                L.PushNumber(4);
                Assert.Equal(LuaStatus.ErrRun, L.PCall(2, 1, 0));
                Assert.Equal("[string \"\r...\"]:6: attempt to call a nil value (global 'DoAnError')", L.ToString(-1));
            }
        }
开发者ID:ygrenier,项目名称:LuaN,代码行数:40,代码来源:LuaStateTest.cs

示例11: TestNext

        public void TestNext()
        {
            LuaState L = null;
            using (L = new LuaState())
            {
                L.NewTable();
                var t = L.GetTop();
                L.PushString("Value A");
                L.SetField(t, "a");
                L.PushString("Value 2");
                L.SetI(t, 2);
                Assert.Equal(1, L.GetTop());

                int count = 0;
                bool foundA = false;
                // First Key
                L.PushNil();
                while (L.Next(t))
                {
                    count++;
                    // => 'key' at index -2 , 'value' as index -1
                    if (LuaType.String == L.Type(-2))
                    {
                        Assert.False(foundA);
                        Assert.Equal(LuaType.String, L.Type(-2));
                        Assert.Equal("a", L.ToString(-2));
                        Assert.Equal(LuaType.String, L.Type(-1));
                        Assert.Equal("Value A", L.ToString(-1));
                        foundA = true;
                    }
                    else
                    {
                        // Second key
                        Assert.Equal(LuaType.Number, L.Type(-2));
                        Assert.Equal(2, L.ToInteger(-2));
                        Assert.Equal(LuaType.String, L.Type(-1));
                        Assert.Equal("Value 2", L.ToString(-1));
                    }
                    // Remove 'value' and keep the 'key' on the stack for the next key
                    L.Pop(1);
                }
                Assert.Equal(2, count);
                Assert.True(foundA);
                // No more key
                // The stack is cleaned
                Assert.Equal(1, L.GetTop());

            }
        }
开发者ID:ygrenier,项目名称:LuaN,代码行数:49,代码来源:LuaStateTest.cs

示例12: TestLoad

 public void TestLoad()
 {
     LuaState L = null;
     using (L = new LuaState())
     {
         String chunk = @"
     a = 'Lua'
     b = ' rocks'
     c=a..b
     return c..'!!'
     ";
         Byte[] chunkBytes = Encoding.ASCII.GetBytes(chunk);
         int curr = 0;
         var st = L.Load((l, ud) => {
             Byte[] res = null;
             if (curr < chunkBytes.Length)
             {
                 int c = Math.Min(7, chunkBytes.Length - curr);
                 res = new Byte[c];
                 Array.Copy(chunkBytes, curr, res, 0, c);
                 curr += c;
             }
             return res;
         }, null, "main", null);
         Assert.Equal(LuaStatus.OK, st);
         st = L.PCall(0, 1, 0);
         Assert.Equal(LuaStatus.OK, st);
         Assert.Equal("Lua rocks!!", L.ToString(-1));
     }
 }
开发者ID:ygrenier,项目名称:LuaN,代码行数:30,代码来源:LuaStateTest.cs


注:本文中的LuaState.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。