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


C# LuaState.Pop方法代码示例

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


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

示例1: GuardDoString

        static bool GuardDoString(LuaState state, String text)
        {
            int ret = state.LoadString(text);
            if (ret != 0)
            {
                LuaStackObject errObj = new LuaStackObject(state, -1);
                state.Pop();
                return false;
            }

            ret = state.PCall(0, -1, 0);
            if (ret != 0)
            {
                LuaStackObject errObj = new LuaStackObject(state, -1);
                state.Pop();
            }

            return true;
        }
开发者ID:rilihong,项目名称:luaplus51-all,代码行数:19,代码来源:Class1.cs

示例2: TestGetTop

        public void TestGetTop()
        {
            LuaState L = null;
            using (L = new LuaState())
            {
                Assert.Equal(0, L.GetTop());
                L.PushNumber(1);
                Assert.Equal(1, L.GetTop());
                L.PushNumber(1);
                Assert.Equal(2, L.GetTop());

                L.Pop(1);
                Assert.Equal(1, L.GetTop());
                L.Pop(1);
                Assert.Equal(0, L.GetTop());
            }
        }
开发者ID:ygrenier,项目名称:LuaN,代码行数:17,代码来源: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: 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

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


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