public void Basic() { var obj = new BasicTestObject(); obj.a = 42; using (var runtime = new LuaRuntime()) { runtime.Globals["obj"] = new LuaTransparentClrObject(obj); var script = @" local old_a = obj.a obj.a = 50 obj.b = 51 obj.c = 'foo' obj.e = 'bar' return { a=old_a, n=obj.square(4), o=obj.sqr(5) } "; using (var result = runtime.DoString(script)) { var t = (LuaTable)result[0]; Assert.AreEqual(50, obj.a, "obj.a"); Assert.AreEqual(51, obj.b, "obj.b"); Assert.AreEqual("foo", obj.C, "obj.C"); Assert.AreEqual("bar", obj.E, "obj.E"); Assert.AreEqual(42, ((LuaNumber)t["a"]).Value, "t.a"); Assert.AreEqual(4 * 4, ((LuaNumber)t["n"]).Value, "t.n"); Assert.AreEqual(5 * 5, ((LuaNumber)t["o"]).Value, "t.o"); } } }
public void Basic() { var obj = new BasicTestObject(); obj.a = 42; using (var runtime = new LuaRuntime()) { runtime.Globals["obj"] = new LuaTransparentClrObject(obj); var script = @" local old_a = obj.a obj.a = 50 obj.b = 51 obj.c = 'foo' obj.e = 'bar' return { a=old_a, n=obj.square(obj, 4), o=obj.sqr(obj, 5) } "; using (var result = runtime.DoString(script)) { var t = (LuaTable)result[0]; Assert.AreEqual(50, obj.a, "obj.a"); Assert.AreEqual(51, obj.b, "obj.b"); Assert.AreEqual("foo", obj.C, "obj.C"); Assert.AreEqual("bar", obj.E, "obj.E"); Assert.AreEqual(42, ((LuaNumber)t["a"]).Value, "t.a"); Assert.AreEqual(4 * 4, ((LuaNumber)t["n"]).Value, "t.n"); Assert.AreEqual(5 * 5, ((LuaNumber)t["o"]).Value, "t.o"); } } }