Exemplo n.º 1
0
		public void LuaDelegateValueTypesByRefParam ()
		{
			using (Lua lua = new Lua ()) {
				lua.DoString ("luanet.load_assembly('NLuaTest')");
				lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
				lua.DoString ("test=TestClass()");
				lua.DoString ("function func(x,y) return x+y; end");
				lua.DoString ("test=TestClass()");
				lua.DoString ("a=test:callDelegate3(func)");
				int a = (int)lua.GetNumber ("a");
				Assert.AreEqual (5, a);
				//Console.WriteLine("delegate returned: "+a);
			}
		}
Exemplo n.º 2
0
		public void TestMultipleOutParameters ()
		{
			using (Lua lua = new Lua ()) {
				TestClass t1 = new TestClass ();
				lua ["netobj"] = t1;
				lua.DoString ("a,b,c=netobj:outValMutiple(2)");
				int a = (int)lua.GetNumber ("a");
				string b = (string)lua.GetString ("b");
				string c = (string)lua.GetString ("c");
				Assert.AreEqual (2, a);
				Assert.AreNotEqual (null, b);
				Assert.AreNotEqual (null, c);
			}
		}
Exemplo n.º 3
0
		public void LuaTableInheritedMethod ()
		{
			using (Lua lua = new Lua ()) {
				lua.DoString ("luanet.load_assembly('NLuaTest')");
				lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
				lua.DoString ("test={}");
				lua.DoString ("function test:overridableMethod(x,y) return x*y; end");
				lua.DoString ("luanet.make_object(test,'NLuaTest.Mock.TestClass')");
				lua.DoString ("test:setVal(3)");
				lua.DoString ("a=test.testval");
				int a = (int)lua.GetNumber ("a");
				lua.DoString ("luanet.free_object(test)");
				Assert.AreEqual (3, a);
				//Console.WriteLine("interface returned: "+a);
			}
		}
Exemplo n.º 4
0
		public void LuaTableOverridedMethod ()
		{
			using (Lua lua = new Lua ()) {
				lua.DoString ("luanet.load_assembly('NLuaTest')");
				lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
				lua.DoString ("test={}");
				lua.DoString ("function test:overridableMethod(x,y) return x*y; end");
				lua.DoString ("luanet.make_object(test,'NLuaTest.Mock.TestClass')");
				lua.DoString ("a=TestClass.callOverridable(test,2,3)");
				int a = (int)lua.GetNumber ("a");
				lua.DoString ("luanet.free_object(test)");
				Assert.AreEqual (6, a);
			}
		}
Exemplo n.º 5
0
		public void TestCoroutine ()
		{
			using (Lua lua = new Lua ()) {
				lua.LoadCLRPackage ();
				lua.RegisterFunction ("func1", null, typeof (TestClass2).GetMethod ("func"));
				lua.DoString ("function yielder() " +
								"a=1;" + "coroutine.yield();" +
								"func1(3,2);" + "coroutine.yield();" + // This line triggers System.NullReferenceException
								"a=2;" + "coroutine.yield();" +
							 "end;" +
							 "co_routine = coroutine.create(yielder);" +
							 "while coroutine.resume(co_routine) do end;");

				double num = lua.GetNumber ("a");
				//Console.WriteLine("a="+num);
				Assert.AreEqual (num, 2d);
			}
		}
Exemplo n.º 6
0
		public void TestCallMethodWithParams2 ()
		{
			using (var l = new Lua ()) {
				l.LoadCLRPackage ();
				l.DoString (" import ('NLuaTest','NLuaTest.Mock') ");
				l.DoString (@"					
					r = TestClass.MethodWithParams(2)			
				");
				int r =  (int)l.GetNumber ("r");
				Assert.AreEqual (0, r, "#1");
			}
		}
Exemplo n.º 7
0
		public void CallGlobalFunctionOneArg ()
		{
			using (Lua lua = new Lua ()) {
				lua.DoString ("a=2\nfunction f(x)\na=a+x\nend");
				lua.GetFunction ("f").Call (1);
				double num = lua.GetNumber ("a");
				//Console.WriteLine("a="+num);
				Assert.AreEqual (num, 3d);
			}
		}
Exemplo n.º 8
0
		public void GetAndSetTable ()
		{
			using (Lua lua = new Lua ()) {
				lua.DoString ("a={b={c=2}}\nb={c=3}");
				LuaTable tab = lua.GetTable ("b");
				lua ["a.b"] = tab;
				double num = lua.GetNumber ("a.b.c");
				//Console.WriteLine("a.b.c="+num);
				Assert.AreEqual (num, 3d);
			}
		}
Exemplo n.º 9
0
		public void NLuaValueTypesOutParam ()
		{
			using (Lua lua = new Lua ()) {
				lua.DoString ("luanet.load_assembly('NLuaTest')");
				lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
				lua.DoString ("test=TestClass()");
				lua.DoString ("itest={}");
				lua.DoString ("function itest:test2(x) return x,x*2; end");
				lua.DoString ("test=TestClass()");
				lua.DoString ("a=test:callInterface2(itest)");
				int a = (int)lua.GetNumber ("a");
				Assert.AreEqual (6, a);
				//Console.WriteLine("interface returned: "+a);
			}
		}
Exemplo n.º 10
0
		public void NLuaAAValueTypes ()
		{
			using (Lua lua = new Lua ()) {
				lua.RegisterLuaClassType (typeof(ITest), typeof(LuaITestClassHandler));
				lua.DoString ("luanet.load_assembly('NLuaTest')");
				lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
				lua.DoString ("test=TestClass()");
				lua.DoString ("itest={}");
				lua.DoString ("function itest:test1(x,y) return x+y; end");
				lua.DoString ("test=TestClass()");
				lua.DoString ("a=test:callInterface1(itest)");
				int a = (int)lua.GetNumber ("a");
				Assert.AreEqual (5, a);
				//Console.WriteLine("interface returned: "+a);
			}
		}
Exemplo n.º 11
0
		public void LuaDelegateReferenceTypesByRefParam ()
		{
			using (Lua lua = new Lua ()) {
				lua.RegisterLuaDelegateType (typeof(TestDelegate7), typeof(LuaTestDelegate7Handler));
				lua.DoString ("luanet.load_assembly('NLuaTest')");
				lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
				lua.DoString ("test=TestClass()");
				lua.DoString ("function func(x,y) return TestClass(x+y.testval); end");
				lua.DoString ("a=test:callDelegate7(func)");
				int a = (int)lua.GetNumber ("a");
				Assert.AreEqual (5, a);
				//Console.WriteLine("delegate returned: "+a);
			}
		}
Exemplo n.º 12
0
		public void LuaDelegateValueTypesOutParam ()
		{
			using (Lua lua = new Lua ()) {
				lua.RegisterLuaDelegateType (typeof(TestDelegate2), typeof(LuaTestDelegate2Handler));
				lua.DoString ("luanet.load_assembly('NLuaTest')");
				lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
				lua.DoString ("test=TestClass()");
				lua.DoString ("function func(x) return x,x*2; end");
				lua.DoString ("test=TestClass()");
				lua.DoString ("a=test:callDelegate2(func)");
				int a = (int)lua.GetNumber ("a");
				Assert.AreEqual (6, a);
				//Console.WriteLine("delegate returned: "+a);
			}
		}
Exemplo n.º 13
0
		public void CallObjectMethodDistinctInterfaces ()
		{
			using (Lua lua = new Lua ()) {
				TestClass t1 = new TestClass ();
				lua ["netobj"] = t1;
				lua.DoString ("a=netobj:foo()");
				lua.DoString ("b=netobj['NLuaTest.Mock.IFoo1.foo']");
				int a = (int)lua.GetNumber ("a");
				int b = (int)lua.GetNumber ("b");
				Assert.AreEqual (5, a);
				Assert.AreEqual (1, b);
				//Console.WriteLine("function returned (from lua)="+a+","+b);
			}
		}
Exemplo n.º 14
0
		public void CallObjectMethodByRefParam ()
		{
			using (Lua lua = new Lua ()) {
				TestClass t1 = new TestClass ();
				lua ["netobj"] = t1;
				lua.DoString ("a,b=netobj:outVal(2,3)");
				int a = (int)lua.GetNumber ("a");
				int b = (int)lua.GetNumber ("b");
				Assert.AreEqual (2, a);
				Assert.AreEqual (5, b);
				//Console.WriteLine("function returned (from lua)="+a+","+b);
			}
		}
Exemplo n.º 15
0
		public void CallObjectMethod ()
		{
			using (Lua lua = new Lua ()) {
				TestClass t1 = new TestClass ();
				t1.testval = 4;
				lua ["netobj"] = t1;
				lua.DoString ("netobj:setVal(3)");
				Assert.AreEqual (3, t1.testval);
				//Console.WriteLine("new val(from C#)="+t1.testval);
				lua.DoString ("val=netobj:getVal()");
				int val = (int)lua.GetNumber ("val");
				Assert.AreEqual (3, val);
				//Console.WriteLine("new val(from Lua)="+val);
			}
		}
Exemplo n.º 16
0
		public void SetGlobalNumber ()
		{
			using (Lua lua = new Lua ()) {
				lua.DoString ("a=2");
				lua ["a"] = 3;
				double num = lua.GetNumber ("a");
				//Console.WriteLine("a="+num);
				Assert.AreEqual (num, 3d);
			}
		}
Exemplo n.º 17
0
		public void SetNumberInTable ()
		{
			using (Lua lua = new Lua ()) {
				lua.DoString ("a={b={c=2}}");
				lua ["a.b.c"] = 3;
				double num = lua.GetNumber ("a.b.c");
				//Console.WriteLine("a.b.c="+num);
				Assert.AreEqual (num, 3d);
			}
		}
Exemplo n.º 18
0
		public void NLuaReferenceTypesByRefParam ()
		{
			using (Lua lua = new Lua ()) {
				lua.DoString ("luanet.load_assembly('NLuaTest')");
				lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
				lua.DoString ("test=TestClass()");
				lua.DoString ("itest={}");
				lua.DoString ("function itest:test7(x,y) return TestClass(x+y.testval); end");
				lua.DoString ("a=test:callInterface7(itest)");
				int a = (int)lua.GetNumber ("a");
				Assert.AreEqual (5, a);
				//Console.WriteLine("interface returned: "+a);
			}
		}
Exemplo n.º 19
0
		public void SetTableNumericField2 ()
		{
			using (Lua lua = new Lua ()) {
				lua.DoString ("a={b={c=2}}");
				LuaTable tab = lua.GetTable ("a");
				tab ["b.c"] = 3;
				double num = lua.GetNumber ("a.b.c");
				//Console.WriteLine("a.b.c="+num);
				Assert.AreEqual (num, 3d);
			}
		}
Exemplo n.º 20
0
		public void NLuaReferenceProperty ()
		{
			using (Lua lua = new Lua ()) {
				lua.DoString ("luanet.load_assembly('NLuaTest')");
				lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
				lua.DoString ("test=TestClass()");
				lua.DoString ("itest={}");
				lua.DoString ("function itest:get_refProp() return TestClass(itest.int_prop); end");
				lua.DoString ("function itest:set_refProp(val) itest.int_prop=val.testval; end");
				lua.DoString ("a=test:callInterface9(itest)");
				int a = (int)lua.GetNumber ("a");
				Assert.AreEqual (3, a);
				//Console.WriteLine("interface returned: "+a);
			}
		}
Exemplo n.º 21
0
		public void CallGlobalFunctionTwoArgs ()
		{
			using (Lua lua = new Lua ()) {
				lua.DoString ("a=2\nfunction f(x,y)\na=x+y\nend");
				lua.GetFunction ("f").Call (1, 3);
				double num = lua.GetNumber ("a");
				//Console.WriteLine("a="+num);
				Assert.AreEqual (num, 4d);
			}
		}
Exemplo n.º 22
0
		public void LuaTableBaseMethod ()
		{
			using (Lua lua = new Lua ()) {
				lua.RegisterLuaClassType (typeof(TestClass), typeof(LuaTestClassHandler));
				lua.DoString ("luanet.load_assembly('NLuaTest')");
				lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
				lua.DoString ("test={}");
				lua.DoString ("function test:overridableMethod(x,y) print(self[base]); return 6 end");
				lua.DoString ("luanet.make_object(test,'NLuaTest.Mock.TestClass')");
				lua.DoString ("a=TestClass.callOverridable(test,2,3)");
				int a = (int)lua.GetNumber ("a");
				lua.DoString ("luanet.free_object(test)");
				Assert.AreEqual (6, a);
				//                 lua.DoString("luanet.load_assembly('NLuaTest')");
				//                 lua.DoString("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
				//                 lua.DoString("test={}");
				//
				//                 lua.DoString("luanet.make_object(test,'NLuaTest.Mock.TestClass')");
				//                              lua.DoString ("function test.overridableMethod(test,x,y) return 2*test.base.overridableMethod(test,x,y); end");
				//                 lua.DoString("a=TestClass.callOverridable(test,2,3)");
				//                 int a = (int)lua.GetNumber("a");
				//                 lua.DoString("luanet.free_object(test)");
				//                 Assert.AreEqual(10, a);
				//Console.WriteLine("interface returned: "+a);
			}
		}