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


C# LuaState.PCall方法代码示例

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


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

 public void TestGetUpvalue()
 {
     LuaState L = null;
     using (L = new LuaState())
     {
         L.PushNumber(23);
         L.PushFunction(l => {
             Assert.Equal(null, l.GetUpvalue(0, 0));
             return 0;
         });
         L.PCall(0, 0, 0);
     }
 }
开发者ID:ygrenier,项目名称:LuaN,代码行数:13,代码来源:LuaStateTest.cs

示例3: TestGetStack

 public void TestGetStack()
 {
     LuaState L = null;
     using (L = new LuaState())
     {
         L.PushNumber(23);
         L.PushFunction(l => {
             var ar = new LuaDebug();
             Assert.Throws<NotImplementedException>(() => l.GetStack(0, ar));
             //Assert.Equal(0, l.GetStack(0, ar));
             //Assert.Equal(0, ar.currentline);
             return 0;
         });
         L.PCall(0, 0, 0);
     }
 }
开发者ID:ygrenier,项目名称:LuaN,代码行数:16,代码来源:LuaStateTest.cs

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

示例5: TestUpvalueJoin

 public void TestUpvalueJoin()
 {
     LuaState L = null;
     using (L = new LuaState())
     {
         L.PushNumber(23);
         L.PushFunction(l => {
             //TODO Do test
             //l.UpvalueJoin(0, 0, 0, 0);
             return 0;
         });
         L.PCall(0, 0, 0);
     }
 }
开发者ID:ygrenier,项目名称:LuaN,代码行数:14,代码来源:LuaStateTest.cs

示例6: TestSetHook

        public void TestSetHook()
        {
            LuaState L = null;
            using (L = new LuaState())
            {
                LuaHook hook = (ILuaState l, LuaDebug ar) => {

                };
                Assert.Throws<NotImplementedException>(() => L.SetHook(hook, LuaHookMask.MaskCall | LuaHookMask.MaskLine | LuaHookMask.MaskCount, 1));
                L.PushNumber(23);
                L.PushFunction(l => {
                    return 0;
                });
                L.PCall(0, 0, 0);
            }
        }
开发者ID:ygrenier,项目名称:LuaN,代码行数:16,代码来源:LuaStateTest.cs

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

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

示例9: Main

        static void Main(string[] args)
        {
            TestGC();

            Class1 cl1 = new Class1();
            LuaState state = new LuaState(true);
            state.GetGlobals().Register("MyCallback", new LuaPlusCallback(MyCallback));
            state.DoString("MyVar = 5");
            //			System.Reflection.MethodInfo info = typeof(Class1).GetMethod("Func2");
            //			state.GetGlobals().Register("Func", null, typeof(Class1).GetMethod("Func")); //typeof(Class1).GetMethod("Func"));
            //			state.DoString("Func(5)");
            LuaObject obj = state.GetGlobal("MyVar");
            state.DoString("MyCallback('Hello')");
            LuaObject funcObj = state.GetGlobal("print");
            //			funcObj.Call("Stuff", 0);

            try
            {
                //				state.DoString( "print('Hello, world!')" );
            }
            catch (Exception e)
            {
            }
            state.DoString("MyTable = { 1, 2, [3] = { \"Hi\" } }");

            double num = obj.GetNumber();
            LuaObject obj3 = state.GetGlobals()["MyTable"];
            String s = obj3.TypeName();
            LuaObject obj2 = new LuaObject(obj);
            obj2.AssignWString(state, "Yo baby!");

            state.DoString("MyTable = { 1, 2, 3, A = 5, 4 }");

            foreach (LuaNode node in state.Globals["MyTable"])
            {
                Console.WriteLine(node);
            }

            try
            {
                LuaObject globObj = state.Globals["MyTable"][1][2];
            }
            catch (LuaException e)
            {
                int hi = 5;
            }

            {
                state.DoString("require 'glob'");
                state.DoString("return glob.match('**')");
                LuaObject filesObj = new LuaObject(state, -1);
                foreach (LuaNode node in filesObj)
                {
                    Console.WriteLine(node.Value.GetString());
                }
            }

            {
                LuaObject globObj = state.GetGlobal("glob");
                LuaObject matchObj = globObj["match"];
                matchObj.Push();
                state.PushString("**");
                state.PCall(1, 1, 0);
                LuaObject filesObj = new LuaObject(state, -1);
                foreach (LuaNode node in filesObj)
                {
                    Console.WriteLine(node.Value.GetString());
                }
            }

            System.IO.FileStream fileStream = new System.IO.FileStream("Out.lua", FileMode.Create);
            LuaStateStreamOutFile outFile = new LuaStateStreamOutFile(fileStream);
            state.DumpObject(outFile, "MyTable", state.Globals["MyTable"]);

            TestIOX();
        }
开发者ID:rilihong,项目名称:luaplus51-all,代码行数:76,代码来源:Class1.cs


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