コード例 #1
0
        [TestMethod] public void InFunction()
        {
            using (var l = new Lua())
            {
                var L = luanet.getstate(l);

                lua.cpcall(L, L2 =>
                {
                    Assert.AreEqual(1, L2.Length);
                    lua.pop(L2, 1);
                    Assert.AreEqual(3, L.Sum(si => si.Type == LUA.T.NONE ? 0 : 1));
                    Assert.AreEqual(LUA.T.NONE, L2[lua.upvalueindex(1)].Type);
                    return(0);
                }, default(IntPtr));
                Assert.AreEqual(0, L.Length);

                lua.CFunction cf = L2 =>
                {
                    Assert.AreEqual(0, L2.Length);
                    Assert.AreEqual(4, L2.Sum(si => si.Type == LUA.T.NONE ? 0 : 1));
                    Assert.AreEqual(LUA.T.BOOLEAN, L2[lua.upvalueindex(1)].Type);
                    return(0);
                };
                lua.pushboolean(L, true);
                lua.pushcclosure(L, cf, 1);
                lua.call(L, 0, 0);

                GC.KeepAlive(cf);
                Assert.AreEqual(0, L.Length);
            }
        }