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


C# LuaState.ToNumber方法代码示例

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


在下文中一共展示了LuaState.ToNumber方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: TestLen

 public void TestLen()
 {
     LuaState L = null;
     using (L = new LuaState())
     {
         L.PushString("Test")
             .PushString("5.6")
             .PushString("5D")
             .PushString("5z")
             ;
         L.Len(1);
         Assert.Equal(4, L.ToNumber(-1));
         L.Len(2);
         Assert.Equal(3, L.ToNumber(-1));
         L.Len(3);
         Assert.Equal(2, L.ToNumber(-1));
         L.Len(4);
         Assert.Equal(2, L.ToNumber(-1));
     }
 }
开发者ID:ygrenier,项目名称:LuaN,代码行数:20,代码来源:LuaStateTest.cs

示例3: TestCall

        public void TestCall()
        {
            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);
                L.Call(2, 1);
                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);
                L.Call(2, 1);
                Assert.Equal(2, L.GetTop());
                Assert.Equal(8, L.ToNumber(-1));

                L.GetGlobal("testB");
                L.PushNumber(12);
                L.PushNumber(4);
                var ex = Assert.Throws<LuaAtPanicException>(() => L.Call(2, 1));
                Assert.Equal("[string \"\r...\"]:6: attempt to call a nil value (global 'DoAnError')", ex.Message);
            }
        }
开发者ID:ygrenier,项目名称:LuaN,代码行数:40,代码来源:LuaStateTest.cs

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

示例5: TestToNumber

        public void TestToNumber()
        {
            LuaState L = null;
            using (L = new LuaState())
            {
                L.PushNil()
                    .PushNumber(123.45)
                    .PushInteger(987)
                    .PushString("Test")
                    .PushString("5.6")
                    .PushString("5D")
                    .PushString("5z")
                    .PushBoolean(true)
                    .PushCClosure(l => 0, 0)
                    //.PushLightUserData(DateTime.Now)
                    .PushGlobalTable()
                    ;

                bool isnum;
                Assert.Equal(0.0, L.ToNumber(1));
                Assert.Equal(0.0, L.ToNumber(1, out isnum));
                Assert.Equal(false, isnum);

                Assert.Equal(123.45, L.ToNumber(2));
                Assert.Equal(123.45, L.ToNumber(2, out isnum));
                Assert.Equal(true, isnum);

                Assert.Equal(987.0, L.ToNumber(3));
                Assert.Equal(987.0, L.ToNumber(3, out isnum));
                Assert.Equal(true, isnum);

                Assert.Equal(0.0, L.ToNumber(4));
                Assert.Equal(0.0, L.ToNumber(4, out isnum));
                Assert.Equal(false, isnum);

                Assert.Equal(5.6, L.ToNumber(5));
                Assert.Equal(5.6, L.ToNumber(5, out isnum));
                Assert.Equal(true, isnum);

                Assert.Equal(0.0, L.ToNumber(6));
                Assert.Equal(0.0, L.ToNumber(7));
                Assert.Equal(0.0, L.ToNumber(8));
                Assert.Equal(0.0, L.ToNumber(9));
                Assert.Equal(0.0, L.ToNumber(10));
                Assert.Equal(0.0, L.ToNumber(11));
                Assert.Equal(0.0, L.ToNumber(12));
            }
        }
开发者ID:ygrenier,项目名称:LuaN,代码行数:48,代码来源:LuaStateTest.cs

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

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

示例8: TestPushNumber

 public void TestPushNumber()
 {
     LuaState L = null;
     using (L = new LuaState())
     {
         L.PushNumber(1234);
         Assert.Equal(1, L.GetTop());
         Assert.Equal(LuaType.Number, L.Type(-1));
         Assert.Equal(1234, L.ToNumber(-1));
     }
 }
开发者ID:ygrenier,项目名称:LuaN,代码行数:11,代码来源:LuaStateTest.cs

示例9: TestCallK

 public void TestCallK()
 {
     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.Throws<NotImplementedException>(() => L.CallK(2, 1, 0, null));
     }
 }
开发者ID:ygrenier,项目名称:LuaN,代码行数:16,代码来源: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


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