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


C# LuaState.GetTop方法代码示例

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


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

示例1: TestArith

 public void TestArith()
 {
     LuaState L = null;
     using (L = new LuaState())
     {
         L.PushNumber(12.34)
             .PushNumber(98.76);
         L.Arith(LuaArithOperator.Add);
         Assert.Equal(1, L.GetTop());
         Assert.Equal(111.1, L.ToNumber(-1), 2);
     }
 }
开发者ID:ygrenier,项目名称:LuaN,代码行数:12,代码来源:LuaStateTest.cs

示例2: TestNewUserData

 public void TestNewUserData()
 {
     LuaState L = null;
     using (L = new LuaState())
     {
         var ptr = L.NewUserData(12);
         Assert.Equal(1, L.GetTop());
         Assert.Equal(LuaType.UserData, L.Type(-1));
     }
 }
开发者ID:ygrenier,项目名称:LuaN,代码行数:10,代码来源:LuaStateTest.cs

示例3: 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

示例4: TestGetSetUserValue

        public void TestGetSetUserValue()
        {
            LuaState L = null;
            using (L = new LuaState())
            {
                L.NewTable();
                Assert.Equal(15, (int)L.GetUserValue(1));

                L.PushString("UserValue");
                L.SetUserValue(1);
                Assert.Equal(2, L.GetTop());

                Assert.Equal(LuaType.String, L.GetUserValue(1));

                L.SetTop(0);
                var ud = L.NewUserData(12);
                Assert.Equal(LuaType.Nil, L.GetUserValue(1));

                L.PushString("UserValue");
                L.SetUserValue(1);
                Assert.Equal(2, L.GetTop());

                Assert.Equal(LuaType.String, L.GetUserValue(1));

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

示例5: TestCreateTable

        public void TestCreateTable()
        {
            LuaState L = null;
            using (L = new LuaState())
            {
                L.CreateTable(0, 0);
                Assert.Equal(1, L.GetTop());
                Assert.Equal(LuaType.Table, L.Type(-1));
                L.Len(-1);
                Assert.Equal(0, L.ToInteger(-1));

                L.CreateTable(3, 7);
                Assert.Equal(3, L.GetTop());
                Assert.Equal(LuaType.Table, L.Type(-1));
                L.Len(-1);
                Assert.Equal(0, L.ToInteger(-1));
            }
        }
开发者ID:ygrenier,项目名称:LuaN,代码行数:18,代码来源:LuaStateTest.cs

示例6: 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

示例7: TestStringToNumber

        public void TestStringToNumber()
        {
            LuaState L = null;
            using (L = new LuaState())
            {
                Assert.Equal(4, L.StringToNumber("5.6"));
                Assert.Equal(1, L.GetTop());
                Assert.Equal(5.6, L.ToNumber(-1));

                Assert.Equal(2, L.StringToNumber("5"));
                Assert.Equal(2, L.GetTop());
                Assert.Equal(5.0, L.ToNumber(-1));

                Assert.Equal(0, L.StringToNumber("5D"));
                Assert.Equal(2, L.GetTop());

                Assert.Equal(0, L.StringToNumber("Test"));
                Assert.Equal(2, L.GetTop());

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

示例8: 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

示例9: TestPushFunction

        public void TestPushFunction()
        {
            LuaState L = null;
            using (L = new LuaState())
            {
                L.PushFunction((l) => {
                    l.PushNumber(12.34);
                    return 0;
                });
                Assert.Equal(1, L.GetTop());
                Assert.Equal(LuaType.Function, L.Type(-1));

                Assert.Throws<ArgumentNullException>(() => L.PushFunction(null));
            }
        }
开发者ID:ygrenier,项目名称:LuaN,代码行数:15,代码来源:LuaStateTest.cs

示例10: TestPushBoolean

 public void TestPushBoolean()
 {
     LuaState L = null;
     using (L = new LuaState())
     {
         L.PushBoolean(true);
         L.PushBoolean(false);
         Assert.Equal(2, L.GetTop());
         Assert.Equal(LuaType.Boolean, L.Type(-1));
         Assert.Equal(LuaType.Boolean, L.Type(-2));
         Assert.Equal(false, L.ToBoolean(-1));
         Assert.Equal(true, L.ToBoolean(-2));
     }
 }
开发者ID:ygrenier,项目名称:LuaN,代码行数:14,代码来源:LuaStateTest.cs

示例11: TestPushCClosure

 public void TestPushCClosure()
 {
     LuaState L = null;
     using (L = new LuaState())
     {
         LuaFunction f = l => 0;
         L.PushCClosure(f, 0);
         Assert.Equal(1, L.GetTop());
         Assert.Equal(LuaType.Function, L.Type(-1));
         Assert.Same(f, L.ToCFunction(-1));
     }
 }
开发者ID:ygrenier,项目名称:LuaN,代码行数:12,代码来源:LuaStateTest.cs

示例12: TestPop

 public void TestPop()
 {
     LuaState L = null;
     using (L = new LuaState())
     {
         L.PushNumber(1);
         L.PushString("Text");
         L.PushNumber(2);
         L.PushString("Text");
         Assert.Equal(4, L.GetTop());
         L.Pop(2);
         Assert.Equal(2, L.GetTop());
         L.Pop(1);
         Assert.Equal(1, L.GetTop());
         L.Pop(2);
         Assert.Equal(-1, L.GetTop());
     }
 }
开发者ID:ygrenier,项目名称:LuaN,代码行数:18,代码来源:LuaStateTest.cs

示例13: 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

示例14: 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

示例15: TestRegister

        public void TestRegister()
        {
            LuaState L = null;
            using (L = new LuaState())
            {
                L.GetGlobal("a");
                Assert.Equal(1, L.GetTop());
                Assert.Equal(LuaType.Nil, L.Type(-1));

                L.Register("a", (l) => {
                    l.PushNumber(12.34);
                    return 0;
                });

                L.GetGlobal("a");
                Assert.Equal(2, L.GetTop());
                Assert.Equal(LuaType.Function, L.Type(-1));
            }
        }
开发者ID:ygrenier,项目名称:LuaN,代码行数:19,代码来源:LuaStateTest.cs


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