Пример #1
0
        public void OpaqueClrObject()
        {
            using (var runtime = new LuaRuntime()) {
                var objValue = new LuaOpaqueClrObject(this);
                runtime.Globals["o"] = objValue;

                using (var o = (LuaClrObjectReference)runtime.Globals["o"]) {
                    Assert.AreSame(objValue, o.ClrObjectValue, "o.ClrObjectValue");
                    Assert.AreSame(this, o.ClrObject, "o.ClrObject");
                }
            }
        }
Пример #2
0
        public void DifferentReferencesToSameClrObjectAreUnequal()
        {
            using (var runtime = new LuaRuntime()) {
                var obj = new LuaOpaqueClrObject(this);

                LuaFunction fn;
                using (var r = runtime.DoString("return function(a, b) return a == b end")) {
                    fn = (LuaFunction)r[0].CopyReference();
                }

                using (var r = fn.Call(obj, obj)) {
                    Assert.AreEqual(1, r.Count, "r.Count");
                    Assert.IsFalse(r[0].ToBoolean(), "r[0]");
                }
            }
        }
Пример #3
0
        public void DifferentReferencesToSameClrObjectAreUnequal()
        {
            using (var runtime = new LuaRuntime()) {
                var obj = new LuaOpaqueClrObject(this);

                LuaFunction fn;
                using (var r = runtime.DoString("return function(a, b) return a == b end")) {
                    fn = (LuaFunction)r[0].CopyReference();
                }

                using (var r = fn.Call(obj, obj)) {
                    Assert.AreEqual(1, r.Count, "r.Count");
                    Assert.IsFalse(r[0].ToBoolean(), "r[0]");
                }
            }
        }
Пример #4
0
        public void ReferenceTableRewriteDoesNotConfuseReferences()
        {
            // Make sure that after a reference table rewrite everything still points where it should.
            using (var runtime = new LuaRuntime()) {
                using (var t1 = runtime.CreateTable())
                    using (var t2 = runtime.CreateTable()) {
                        t1["foo"]     = "bar";
                        t2[5]         = 6;
                        t2["fixture"] = new LuaOpaqueClrObject(this);

                        // 1000 cycles should trigger a rewrite.
                        foreach (var t in Enumerable.Range(1, 1000).Select(j => runtime.CreateTable()).ToList())
                        {
                            t.Dispose();
                        }

                        Assert.AreEqual("bar", t1["foo"].ToString());
                        Assert.AreEqual(6, t2[5].ToNumber());
                        using (var clrRef = (LuaClrObjectReference)t2["fixture"]) {
                            Assert.AreSame(this, clrRef.ClrObject);
                        }
                    }
            }
        }
Пример #5
0
        public void ReferenceTableRewriteDoesNotConfuseReferences()
        {
            // Make sure that after a reference table rewrite everything still points where it should.
            using (var runtime = new LuaRuntime()) {
                using (var t1 = runtime.CreateTable())
                using (var t2 = runtime.CreateTable()) {
                    t1["foo"] = "bar";
                    t2[5] = 6;
                    t2["fixture"] = new LuaOpaqueClrObject(this);

                    // 1000 cycles should trigger a rewrite.
                    foreach (var t in Enumerable.Range(1, 1000).Select(j => runtime.CreateTable()).ToList()) {
                        t.Dispose();
                    }

                    Assert.AreEqual("bar", t1["foo"].ToString());
                    Assert.AreEqual(6, t2[5].ToNumber());
                    using (var clrRef = (LuaOpaqueClrObjectReference)t2["fixture"]) {
                        Assert.AreSame(this, clrRef.ClrObject);
                    }
                }
            }
        }
Пример #6
0
        public void OpaqueClrObject()
        {
            using (var runtime = new LuaRuntime()) {
                var objValue = new LuaOpaqueClrObject(this);
                runtime.Globals["o"] = objValue;

                using (var o = (LuaClrObjectReference)runtime.Globals["o"]) {
                    Assert.AreSame(objValue, o.ClrObjectValue, "o.ClrObjectValue");
                    Assert.AreSame(this, o.ClrObject, "o.ClrObject");
                }
            }
        }