"packages/KeraLua.1.0.24/lib/xamarinwatchos/KeraLua.xml" did not exist on "a7bec7fb031b862a5d6054c0183ddaca927d8d04"
Commit 5fc72461 authored by Vinicius Jarina's avatar Vinicius Jarina
Browse files

Mono-style format.

parent a0e1671c
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LuaInterfaceTest.Mock
......@@ -9,25 +8,24 @@ namespace LuaInterfaceTest.Mock
{
public event EventHandler<EventArgs> Clicked;
protected virtual void OnEntityClicked(EventArgs e)
protected virtual void OnEntityClicked (EventArgs e)
{
EventHandler<EventArgs> handler = Clicked;
if (handler != null)
{
if (handler != null) {
// Use the () operator to raise the event.
handler(this, e);
handler (this, e);
}
}
public Entity()
public Entity ()
{
}
public void Click()
public void Click ()
{
OnEntityClicked(new EventArgs());
OnEntityClicked (new EventArgs ());
}
}
}
......@@ -10,23 +10,23 @@ using LuaInterface.Exceptions;
namespace LuaInterfaceTest
{
[TestFixture]
public class LuaTests
{
[TestFixture]
public class LuaTests
{
/*
* Tests capturing an exception
*/
[Test]
public void ThrowException ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('mscorlib')");
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
lua.DoString ("err,errMsg=pcall(test.exceptionMethod,test)");
bool err = (bool) lua ["err"];
Exception errMsg = (Exception) lua ["errMsg"];
bool err = (bool)lua ["err"];
Exception errMsg = (Exception)lua ["errMsg"];
Assert.False (err);
Assert.NotNull (errMsg.InnerException);
Assert.AreEqual ("exception test", errMsg.InnerException.Message);
......@@ -39,7 +39,7 @@ public class LuaTests
[Test]
public void ThrowUncaughtException ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('mscorlib')");
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
......@@ -49,7 +49,7 @@ public class LuaTests
lua.DoString ("test:exceptionMethod()");
//failed
Assert.True (false);
} catch (Exception e) {
} catch (Exception) {
//passed
Assert.True (true);
}
......@@ -63,16 +63,16 @@ public class LuaTests
[Test]
public void TestNullable ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('mscorlib')");
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
lua.DoString ("val=test.NullableBool");
Assert.Null ( (object) lua ["val"]);
Assert.Null ((object)lua ["val"]);
lua.DoString ("test.NullableBool = true");
lua.DoString ("val=test.NullableBool");
Assert.True ( (bool) lua ["val"]);
Assert.True ((bool)lua ["val"]);
}
}
......@@ -83,7 +83,7 @@ public class LuaTests
[Test]
public void TestStructs ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
......@@ -91,14 +91,14 @@ public class LuaTests
lua.DoString ("struct=TestStruct(2)");
lua.DoString ("test.Struct = struct");
lua.DoString ("val=test.Struct.val");
Assert.AreEqual (2.0d, (double) lua ["val"]);
Assert.AreEqual (2.0d, (double)lua ["val"]);
}
}
[Test]
public void TestMethodOverloads ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('mscorlib')");
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
......@@ -117,7 +117,7 @@ public class LuaTests
long startingMem = System.Diagnostics.Process.GetCurrentProcess ().WorkingSet64;
for (int i = 0; i < 100; i++) {
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
_Calc (lua, i);
}
}
......@@ -141,16 +141,16 @@ public class LuaTests
);
lua.DoString ("function calcVP(a,b) return a+b end");
LuaFunction lf = lua.GetFunction ("calcVP");
Object[] ret = lf.Call (i, 20);
lf.Call (i, 20);
}
[Test]
public void TestThreading ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
object lua_locker = new object ();
DoWorkClass doWork = new DoWorkClass ();
lua.RegisterFunction ("dowork", doWork, typeof (DoWorkClass).GetMethod ("DoWork") );
lua.RegisterFunction ("dowork", doWork, typeof(DoWorkClass).GetMethod ("DoWork"));
bool failureDetected = false;
int completed = 0;
int iterations = 10;
......@@ -167,7 +167,7 @@ public class LuaTests
}
completed++;
}) );
}));
}
while (completed < iterations && !failureDetected)
......@@ -180,7 +180,7 @@ public class LuaTests
[Test]
public void TestPrivateMethod ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('mscorlib')");
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
......@@ -203,10 +203,10 @@ public class LuaTests
[Test]
public void TestFunctions ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('mscorlib')");
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.RegisterFunction ("p", null, typeof (System.Console).GetMethod ("WriteLine", new Type [] { typeof (String) }) );
lua.RegisterFunction ("p", null, typeof(System.Console).GetMethod ("WriteLine", new Type [] { typeof(String) }));
/// Lua command that works (prints to console)
lua.DoString ("p('Foo')");
/// Yet this works...
......@@ -224,14 +224,14 @@ public class LuaTests
[Test]
public void LuaTableOverridedMethod ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("test={}");
lua.DoString ("function test:overridableMethod(x,y) return x*y; end");
lua.DoString ("luanet.make_object(test,'LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("a=TestClass.callOverridable(test,2,3)");
int a = (int) lua.GetNumber ("a");
int a = (int)lua.GetNumber ("a");
lua.DoString ("luanet.free_object(test)");
Assert.AreEqual (6, a);
}
......@@ -245,7 +245,7 @@ public class LuaTests
[Test]
public void LuaTableInheritedMethod ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("test={}");
......@@ -253,7 +253,7 @@ public class LuaTests
lua.DoString ("luanet.make_object(test,'LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("test:setVal(3)");
lua.DoString ("a=test.testval");
int a = (int) lua.GetNumber ("a");
int a = (int)lua.GetNumber ("a");
lua.DoString ("luanet.free_object(test)");
Assert.AreEqual (3, a);
//Console.WriteLine("interface returned: "+a);
......@@ -286,14 +286,14 @@ public class LuaTests
[Test]
public void TestEventException ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
//Register a C# function
MethodInfo testException = this.GetType ().GetMethod ("_TestException", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance, null, new Type [] {
typeof (float),
typeof (float)
typeof(float),
typeof(float)
}, null);
lua.RegisterFunction ("Multiply", this, testException);
lua.RegisterLuaDelegateType (typeof (EventHandler<EventArgs>), typeof (LuaEventArgsHandler) );
lua.RegisterLuaDelegateType (typeof(EventHandler<EventArgs>), typeof(LuaEventArgsHandler));
//create the lua event handler code for the entity
//includes the bad code!
lua.DoString ("function OnClick(sender, eventArgs)\r\n" +
......@@ -319,7 +319,7 @@ public class LuaTests
entity.Click ();
//failed
Assert.True (false);
} catch (LuaException e) {
} catch (LuaException) {
//passed
Assert.True (true);
}
......@@ -329,11 +329,11 @@ public class LuaTests
[Test]
public void TestExceptionWithChunkOverload ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
try {
lua.DoString ("thiswillthrowanerror", "MyChunk");
} catch (Exception e) {
Assert.True (e.Message.StartsWith ("[string \"MyChunk\"]") );
Assert.True (e.Message.StartsWith ("[string \"MyChunk\"]"));
}
}
}
......@@ -346,9 +346,9 @@ public class LuaTests
//TestClassGeneric<string> genericClass = new TestClassGeneric<string>();
//lua.RegisterFunction("genericMethod", genericClass, typeof(TestClassGeneric<>).GetMethod("GenericMethod"));
//lua.RegisterFunction("regularMethod", genericClass, typeof(TestClassGeneric<>).GetMethod("RegularMethod"));
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
TestClassWithGenericMethod classWithGenericMethod = new TestClassWithGenericMethod ();
lua.RegisterFunction ("genericMethod2", classWithGenericMethod, typeof (TestClassWithGenericMethod).GetMethod ("GenericMethod") );
lua.RegisterFunction ("genericMethod2", classWithGenericMethod, typeof(TestClassWithGenericMethod).GetMethod ("GenericMethod"));
try {
lua.DoString ("genericMethod2(100)");
......@@ -356,7 +356,7 @@ public class LuaTests
}
Assert.True (classWithGenericMethod.GenericMethodSuccess);
Assert.True (classWithGenericMethod.Validate<double> (100) ); //note the gotcha: numbers are all being passed to generic methods as doubles
Assert.True (classWithGenericMethod.Validate<double> (100)); //note the gotcha: numbers are all being passed to generic methods as doubles
try {
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
......@@ -374,16 +374,15 @@ public class LuaTests
[Test]
public void RegisterFunctionStressTest ()
{
LuaFunction fc = null;
const int Count = 200; // it seems to work with 41
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
MyClass t = new MyClass ();
for (int i = 1; i < Count - 1; ++i) {
fc = lua.RegisterFunction ("func" + i, t, typeof (MyClass).GetMethod ("Func1") );
lua.RegisterFunction ("func" + i, t, typeof(MyClass).GetMethod ("Func1"));
}
fc = lua.RegisterFunction ("func" + (Count - 1), t, typeof (MyClass).GetMethod ("Func1") );
lua.RegisterFunction ("func" + (Count - 1), t, typeof(MyClass).GetMethod ("Func1"));
lua.DoString ("print(func1())");
}
}
......@@ -391,13 +390,13 @@ public class LuaTests
[Test]
public void TestMultipleOutParameters ()
{
using (Lua lua = new Lua () ) {
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");
int a = (int)lua.GetNumber ("a");
string b = (string)lua.GetString ("b");
string c = (string)lua.GetString ("c");
Assert.AreEqual (2, a);
Assert.NotNull (b);
Assert.NotNull (c);
......@@ -411,7 +410,7 @@ public class LuaTests
//See: http://code.google.com/p/luainterface/issues/detail?id=5
//number of iterations to test
int count = 1000;
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
for (int i = 0; i < count; i++) {
lua.LoadString ("abc = 'def'", string.Empty);
}
......@@ -426,7 +425,7 @@ public class LuaTests
//See: http://code.google.com/p/luainterface/issues/detail?id=5
//number of iterations to test
int count = 1000;
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
for (int i = 0; i < count; i++) {
lua.LoadFile (Environment.CurrentDirectory + System.IO.Path.DirectorySeparatorChar + "test.lua");
}
......@@ -437,14 +436,14 @@ public class LuaTests
[Test]
public void TestRegisterFunction ()
{
using (Lua lua = new Lua () ) {
lua.RegisterFunction ("func1", null, typeof (TestClass2).GetMethod ("func") );
using (Lua lua = new Lua ()) {
lua.RegisterFunction ("func1", null, typeof(TestClass2).GetMethod ("func"));
object[] vals1 = lua.GetFunction ("func1").Call (2, 3);
Assert.AreEqual (5.0f, Convert.ToSingle (vals1 [0]) );
Assert.AreEqual (5.0f, Convert.ToSingle (vals1 [0]));
TestClass2 obj = new TestClass2 ();
lua.RegisterFunction ("func2", obj, typeof (TestClass2).GetMethod ("funcInstance") );
lua.RegisterFunction ("func2", obj, typeof(TestClass2).GetMethod ("funcInstance"));
vals1 = lua.GetFunction ("func2").Call (2, 3);
Assert.AreEqual (5.0f, Convert.ToSingle (vals1 [0]) );
Assert.AreEqual (5.0f, Convert.ToSingle (vals1 [0]));
}
}
......@@ -454,7 +453,7 @@ public class LuaTests
[Test]
public void DoString ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
object[] res = lua.DoString ("a=2\nreturn a,3");
//Console.WriteLine("a="+res[0]+", b="+res[1]);
Assert.AreEqual (res [0], 2d);
......@@ -467,7 +466,7 @@ public class LuaTests
[Test]
public void GetGlobalNumber ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("a=2");
double num = lua.GetNumber ("a");
//Console.WriteLine("a="+num);
......@@ -480,7 +479,7 @@ public class LuaTests
[Test]
public void SetGlobalNumber ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("a=2");
lua ["a"] = 3;
double num = lua.GetNumber ("a");
......@@ -495,7 +494,7 @@ public class LuaTests
[Test]
public void GetNumberInTable ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("a={b={c=2}}");
double num = lua.GetNumber ("a.b.c");
//Console.WriteLine("a.b.c="+num);
......@@ -509,7 +508,7 @@ public class LuaTests
[Test]
public void SetNumberInTable ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("a={b={c=2}}");
lua ["a.b.c"] = 3;
double num = lua.GetNumber ("a.b.c");
......@@ -523,7 +522,7 @@ public class LuaTests
[Test]
public void GetGlobalString ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("a=\"test\"");
string str = lua.GetString ("a");
//Console.WriteLine("a="+str);
......@@ -536,7 +535,7 @@ public class LuaTests
[Test]
public void SetGlobalString ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("a=\"test\"");
lua ["a"] = "new test";
string str = lua.GetString ("a");
......@@ -551,7 +550,7 @@ public class LuaTests
[Test]
public void GetStringInTable ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("a={b={c=\"test\"}}");
string str = lua.GetString ("a.b.c");
//Console.WriteLine("a.b.c="+str);
......@@ -565,7 +564,7 @@ public class LuaTests
[Test]
public void SetStringInTable ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("a={b={c=\"test\"}}");
lua ["a.b.c"] = "new test";
string str = lua.GetString ("a.b.c");
......@@ -579,7 +578,7 @@ public class LuaTests
[Test]
public void GetAndSetTable ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("a={b={c=2}}\nb={c=3}");
LuaTable tab = lua.GetTable ("b");
lua ["a.b"] = tab;
......@@ -594,10 +593,10 @@ public class LuaTests
[Test]
public void GetTableNumericField1 ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("a={b={c=2}}");
LuaTable tab = lua.GetTable ("a.b");
double num = (double) tab ["c"];
double num = (double)tab ["c"];
//Console.WriteLine("a.b.c="+num);
Assert.AreEqual (num, 2d);
}
......@@ -609,10 +608,10 @@ public class LuaTests
[Test]
public void GetTableNumericField2 ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("a={b={c=2}}");
LuaTable tab = lua.GetTable ("a");
double num = (double) tab ["b.c"];
double num = (double)tab ["b.c"];
//Console.WriteLine("a.b.c="+num);
Assert.AreEqual (num, 2d);
}
......@@ -623,7 +622,7 @@ public class LuaTests
[Test]
public void SetTableNumericField1 ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("a={b={c=2}}");
LuaTable tab = lua.GetTable ("a.b");
tab ["c"] = 3;
......@@ -639,7 +638,7 @@ public class LuaTests
[Test]
public void SetTableNumericField2 ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("a={b={c=2}}");
LuaTable tab = lua.GetTable ("a");
tab ["b.c"] = 3;
......@@ -654,10 +653,10 @@ public class LuaTests
[Test]
public void GetTableStringField1 ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("a={b={c=\"test\"}}");
LuaTable tab = lua.GetTable ("a.b");
string str = (string) tab ["c"];
string str = (string)tab ["c"];
//Console.WriteLine("a.b.c="+str);
Assert.AreEqual (str, "test");
}
......@@ -669,10 +668,10 @@ public class LuaTests
[Test]
public void GetTableStringField2 ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("a={b={c=\"test\"}}");
LuaTable tab = lua.GetTable ("a");
string str = (string) tab ["b.c"];
string str = (string)tab ["b.c"];
//Console.WriteLine("a.b.c="+str);
Assert.AreEqual (str, "test");
}
......@@ -683,7 +682,7 @@ public class LuaTests
[Test]
public void SetTableStringField1 ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("a={b={c=\"test\"}}");
LuaTable tab = lua.GetTable ("a.b");
tab ["c"] = "new test";
......@@ -699,7 +698,7 @@ public class LuaTests
[Test]
public void SetTableStringField2 ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("a={b={c=\"test\"}}");
LuaTable tab = lua.GetTable ("a");
tab ["b.c"] = "new test";
......@@ -714,7 +713,7 @@ public class LuaTests
[Test]
public void CallGlobalFunctionNoArgs ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("a=2\nfunction f()\na=3\nend");
lua.GetFunction ("f").Call ();
double num = lua.GetNumber ("a");
......@@ -728,7 +727,7 @@ public class LuaTests
[Test]
public void CallGlobalFunctionOneArg ()
{
using (Lua lua = new Lua () ) {
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");
......@@ -742,7 +741,7 @@ public class LuaTests
[Test]
public void CallGlobalFunctionTwoArgs ()
{
using (Lua lua = new Lua () ) {
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");
......@@ -756,12 +755,12 @@ public class LuaTests
[Test]
public void CallGlobalFunctionOneReturn ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("function f(x)\nreturn x+2\nend");
object[] ret = lua.GetFunction ("f").Call (3);
//Console.WriteLine("ret="+ret[0]);
Assert.AreEqual (1, ret.Length);
Assert.AreEqual (5, (double) ret [0]);
Assert.AreEqual (5, (double)ret [0]);
}
}
/*
......@@ -770,13 +769,13 @@ public class LuaTests
[Test]
public void CallGlobalFunctionTwoReturns ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("function f(x,y)\nreturn x,x+y\nend");
object[] ret = lua.GetFunction ("f").Call (3, 2);
//Console.WriteLine("ret="+ret[0]+","+ret[1]);
Assert.AreEqual (2, ret.Length);
Assert.AreEqual (3, (double) ret [0]);
Assert.AreEqual (5, (double) ret [1]);
Assert.AreEqual (3, (double)ret [0]);
Assert.AreEqual (5, (double)ret [1]);
}
}
/*
......@@ -785,13 +784,13 @@ public class LuaTests
[Test]
public void CallTableFunctionTwoReturns ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("a={}\nfunction a.f(x,y)\nreturn x,x+y\nend");
object[] ret = lua.GetFunction ("a.f").Call (3, 2);
//Console.WriteLine("ret="+ret[0]+","+ret[1]);
Assert.AreEqual (2, ret.Length);
Assert.AreEqual (3, (double) ret [0]);
Assert.AreEqual (5, (double) ret [1]);
Assert.AreEqual (3, (double)ret [0]);
Assert.AreEqual (5, (double)ret [1]);
}
}
/*
......@@ -800,13 +799,13 @@ public class LuaTests
[Test]
public void SetGlobalObject ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
TestClass t1 = new TestClass ();
t1.testval = 4;
lua ["netobj"] = t1;
object o = lua ["netobj"];
Assert.True (o is TestClass);
TestClass t2 = (TestClass) lua ["netobj"];
TestClass t2 = (TestClass)lua ["netobj"];
Assert.AreEqual (t2.testval, 4);
Assert.True (t1 == t2);
}
......@@ -834,13 +833,13 @@ public class LuaTests
[Test]
public void SetTableObjectField1 ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("a={b={c=\"test\"}}");
LuaTable tab = lua.GetTable ("a.b");
TestClass t1 = new TestClass ();
t1.testval = 4;
tab ["c"] = t1;
TestClass t2 = (TestClass) lua ["a.b.c"];
TestClass t2 = (TestClass)lua ["a.b.c"];
//Console.WriteLine("a.b.c="+t2.testval);
Assert.AreEqual (t2.testval, 4);
Assert.True (t1 == t2);
......@@ -852,12 +851,12 @@ public class LuaTests
[Test]
public void AccessObjectField ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
TestClass t1 = new TestClass ();
t1.val = 4;
lua ["netobj"] = t1;
lua.DoString ("var=netobj.val");
double var = (double) lua ["var"];
double var = (double)lua ["var"];
//Console.WriteLine("value from Lua="+var);
Assert.AreEqual (4, var);
lua.DoString ("netobj.val=3");
......@@ -872,12 +871,12 @@ public class LuaTests
[Test]
public void AccessObjectProperty ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
TestClass t1 = new TestClass ();
t1.testval = 4;
lua ["netobj"] = t1;
lua.DoString ("var=netobj.testval");
double var = (double) lua ["var"];
double var = (double)lua ["var"];
//Console.WriteLine("value from Lua="+var);
Assert.AreEqual (4, var);
lua.DoString ("netobj.testval=3");
......@@ -891,7 +890,7 @@ public class LuaTests
[Test]
public void CallObjectMethod ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
TestClass t1 = new TestClass ();
t1.testval = 4;
lua ["netobj"] = t1;
......@@ -899,7 +898,7 @@ public class LuaTests
Assert.AreEqual (3, t1.testval);
//Console.WriteLine("new val(from C#)="+t1.testval);
lua.DoString ("val=netobj:getVal()");
int val = (int) lua.GetNumber ("val");
int val = (int)lua.GetNumber ("val");
Assert.AreEqual (3, val);
//Console.WriteLine("new val(from Lua)="+val);
}
......@@ -910,11 +909,11 @@ public class LuaTests
[Test]
public void CallObjectMethodByType ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
TestClass t1 = new TestClass ();
lua ["netobj"] = t1;
lua.DoString ("netobj:setVal('str')");
Assert.AreEqual ("str", t1.getStrVal () );
Assert.AreEqual ("str", t1.getStrVal ());
//Console.WriteLine("new val(from C#)="+t1.getStrVal());
}
}
......@@ -925,12 +924,12 @@ public class LuaTests
[Test]
public void CallObjectMethodOutParam ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
TestClass t1 = new TestClass ();
lua ["netobj"] = t1;
lua.DoString ("a,b=netobj:outVal()");
int a = (int) lua.GetNumber ("a");
int b = (int) lua.GetNumber ("b");
int a = (int)lua.GetNumber ("a");
int b = (int)lua.GetNumber ("b");
Assert.AreEqual (3, a);
Assert.AreEqual (5, b);
//Console.WriteLine("function returned (from lua)="+a+","+b);
......@@ -943,12 +942,12 @@ public class LuaTests
[Test]
public void CallObjectMethodOverloadedOutParam ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
TestClass t1 = new TestClass ();
lua ["netobj"] = t1;
lua.DoString ("a,b=netobj:outVal(2)");
int a = (int) lua.GetNumber ("a");
int b = (int) lua.GetNumber ("b");
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);
......@@ -960,12 +959,12 @@ public class LuaTests
[Test]
public void CallObjectMethodByRefParam ()
{
using (Lua lua = new Lua () ) {
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");
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);
......@@ -978,13 +977,13 @@ public class LuaTests
[Test]
public void CallObjectMethodDistinctInterfaces ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
TestClass t1 = new TestClass ();
lua ["netobj"] = t1;
lua.DoString ("a=netobj:foo()");
lua.DoString ("b=netobj['LuaInterfaceTest.Mock.IFoo1.foo']");
int a = (int) lua.GetNumber ("a");
int b = (int) lua.GetNumber ("b");
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);
......@@ -996,13 +995,13 @@ public class LuaTests
[Test]
public void CreateNetObjectNoArgsCons ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly(\"LuaInterfaceTest\")");
lua.DoString ("TestClass=luanet.import_type(\"LuaInterfaceTest.Mock.TestClass\")");
lua.DoString ("test=TestClass()");
lua.DoString ("test:setVal(3)");
object[] res = lua.DoString ("return test");
TestClass test = (TestClass) res [0];
TestClass test = (TestClass)res [0];
//Console.WriteLine("returned: "+test.testval);
Assert.AreEqual (3, test.testval);
}
......@@ -1013,12 +1012,12 @@ public class LuaTests
[Test]
public void CreateNetObjectOneArgCons ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly(\"LuaInterfaceTest\")");
lua.DoString ("TestClass=luanet.import_type(\"LuaInterfaceTest.Mock.TestClass\")");
lua.DoString ("test=TestClass(3)");
object[] res = lua.DoString ("return test");
TestClass test = (TestClass) res [0];
TestClass test = (TestClass)res [0];
//Console.WriteLine("returned: "+test.testval);
Assert.AreEqual (3, test.testval);
}
......@@ -1029,14 +1028,14 @@ public class LuaTests
[Test]
public void CreateNetObjectOverloadedCons ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly(\"LuaInterfaceTest\")");
lua.DoString ("TestClass=luanet.import_type(\"LuaInterfaceTest.Mock.TestClass\")");
lua.DoString ("test=TestClass('str')");
object[] res = lua.DoString ("return test");
TestClass test = (TestClass) res [0];
TestClass test = (TestClass)res [0];
//Console.WriteLine("returned: "+test.getStrVal());
Assert.AreEqual ("str", test.getStrVal () );
Assert.AreEqual ("str", test.getStrVal ());
}
}
/*
......@@ -1045,7 +1044,7 @@ public class LuaTests
[Test]
public void ReadArrayField ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
string[] arr = new string [] { "str1", "str2", "str3" };
lua ["netobj"] = arr;
lua.DoString ("val=netobj[1]");
......@@ -1060,7 +1059,7 @@ public class LuaTests
[Test]
public void WriteArrayField ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
string[] arr = new string [] { "str1", "str2", "str3" };
lua ["netobj"] = arr;
lua.DoString ("netobj[1]='test'");
......@@ -1074,12 +1073,12 @@ public class LuaTests
[Test]
public void CreateArray ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly(\"LuaInterfaceTest\")");
lua.DoString ("TestClass=luanet.import_type(\"LuaInterfaceTest.Mock.TestClass\")");
lua.DoString ("arr=TestClass[3]");
lua.DoString ("for i=0,2 do arr[i]=TestClass(i+1) end");
TestClass[] arr = (TestClass[]) lua ["arr"];
TestClass[] arr = (TestClass[])lua ["arr"];
Assert.AreEqual (arr [1].testval, 2);
}
}
......@@ -1090,15 +1089,15 @@ public class LuaTests
[Test]
public void LuaDelegateValueTypes ()
{
using (Lua lua = new Lua () ) {
lua.RegisterLuaDelegateType (typeof (TestDelegate1), typeof (LuaTestDelegate1Handler) );
using (Lua lua = new Lua ()) {
lua.RegisterLuaDelegateType (typeof(TestDelegate1), typeof(LuaTestDelegate1Handler));
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
lua.DoString ("function func(x,y) return x+y; end");
lua.DoString ("test=TestClass()");
lua.DoString ("a=test:callDelegate1(func)");
int a = (int) lua.GetNumber ("a");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (5, a);
//Console.WriteLine("delegate returned: "+a);
}
......@@ -1110,15 +1109,15 @@ public class LuaTests
[Test]
public void LuaDelegateValueTypesOutParam ()
{
using (Lua lua = new Lua () ) {
lua.RegisterLuaDelegateType (typeof (TestDelegate2), typeof (LuaTestDelegate2Handler) );
using (Lua lua = new Lua ()) {
lua.RegisterLuaDelegateType (typeof(TestDelegate2), typeof(LuaTestDelegate2Handler));
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.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");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (6, a);
//Console.WriteLine("delegate returned: "+a);
}
......@@ -1130,15 +1129,15 @@ public class LuaTests
[Test]
public void LuaDelegateValueTypesByRefParam ()
{
using (Lua lua = new Lua () ) {
lua.RegisterLuaDelegateType (typeof (TestDelegate3), typeof (LuaTestDelegate3Handler) );
using (Lua lua = new Lua ()) {
lua.RegisterLuaDelegateType (typeof(TestDelegate3), typeof(LuaTestDelegate3Handler));
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.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");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (5, a);
//Console.WriteLine("delegate returned: "+a);
}
......@@ -1150,15 +1149,15 @@ public class LuaTests
[Test]
public void LuaDelegateValueTypesReturnReferenceType ()
{
using (Lua lua = new Lua () ) {
lua.RegisterLuaDelegateType (typeof (TestDelegate4), typeof (LuaTestDelegate4Handler) );
using (Lua lua = new Lua ()) {
lua.RegisterLuaDelegateType (typeof(TestDelegate4), typeof(LuaTestDelegate4Handler));
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
lua.DoString ("function func(x,y) return TestClass(x+y); end");
lua.DoString ("test=TestClass()");
lua.DoString ("a=test:callDelegate4(func)");
int a = (int) lua.GetNumber ("a");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (5, a);
//Console.WriteLine("delegate returned: "+a);
}
......@@ -1170,14 +1169,14 @@ public class LuaTests
[Test]
public void LuaDelegateReferenceTypes ()
{
using (Lua lua = new Lua () ) {
lua.RegisterLuaDelegateType (typeof (TestDelegate5), typeof (LuaTestDelegate5Handler) );
using (Lua lua = new Lua ()) {
lua.RegisterLuaDelegateType (typeof(TestDelegate5), typeof(LuaTestDelegate5Handler));
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
lua.DoString ("function func(x,y) return x.testval+y.testval; end");
lua.DoString ("a=test:callDelegate5(func)");
int a = (int) lua.GetNumber ("a");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (5, a);
//Console.WriteLine("delegate returned: "+a);
}
......@@ -1189,15 +1188,15 @@ public class LuaTests
[Test]
public void LuaDelegateReferenceTypesOutParam ()
{
using (Lua lua = new Lua () ) {
lua.RegisterLuaDelegateType (typeof (TestDelegate6), typeof (LuaTestDelegate6Handler) );
using (Lua lua = new Lua ()) {
lua.RegisterLuaDelegateType (typeof(TestDelegate6), typeof(LuaTestDelegate6Handler));
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
lua.DoString ("function func(x) return x,TestClass(x*2); end");
lua.DoString ("test=TestClass()");
lua.DoString ("a=test:callDelegate6(func)");
int a = (int) lua.GetNumber ("a");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (6, a);
//Console.WriteLine("delegate returned: "+a);
}
......@@ -1209,14 +1208,14 @@ public class LuaTests
[Test]
public void LuaDelegateReferenceTypesByRefParam ()
{
using (Lua lua = new Lua () ) {
lua.RegisterLuaDelegateType (typeof (TestDelegate7), typeof (LuaTestDelegate7Handler) );
using (Lua lua = new Lua ()) {
lua.RegisterLuaDelegateType (typeof(TestDelegate7), typeof(LuaTestDelegate7Handler));
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.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");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (5, a);
//Console.WriteLine("delegate returned: "+a);
}
......@@ -1230,8 +1229,8 @@ public class LuaTests
[Test]
public void LuaInterfaceAAValueTypes ()
{
using (Lua lua = new Lua () ) {
lua.RegisterLuaClassType (typeof (ITest), typeof (LuaITestClassHandler) );
using (Lua lua = new Lua ()) {
lua.RegisterLuaClassType (typeof(ITest), typeof(LuaITestClassHandler));
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
......@@ -1239,7 +1238,7 @@ public class LuaTests
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");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (5, a);
//Console.WriteLine("interface returned: "+a);
}
......@@ -1252,7 +1251,7 @@ public class LuaTests
[Test]
public void LuaInterfaceValueTypesOutParam ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
......@@ -1260,7 +1259,7 @@ public class LuaTests
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");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (6, a);
//Console.WriteLine("interface returned: "+a);
}
......@@ -1273,7 +1272,7 @@ public class LuaTests
[Test]
public void LuaInterfaceValueTypesByRefParam ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
......@@ -1281,7 +1280,7 @@ public class LuaTests
lua.DoString ("function itest:test3(x,y) return x+y; end");
lua.DoString ("test=TestClass()");
lua.DoString ("a=test:callInterface3(itest)");
int a = (int) lua.GetNumber ("a");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (5, a);
//Console.WriteLine("interface returned: "+a);
}
......@@ -1294,7 +1293,7 @@ public class LuaTests
[Test]
public void LuaInterfaceValueTypesReturnReferenceType ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
......@@ -1302,7 +1301,7 @@ public class LuaTests
lua.DoString ("function itest:test4(x,y) return TestClass(x+y); end");
lua.DoString ("test=TestClass()");
lua.DoString ("a=test:callInterface4(itest)");
int a = (int) lua.GetNumber ("a");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (5, a);
//Console.WriteLine("interface returned: "+a);
}
......@@ -1314,7 +1313,7 @@ public class LuaTests
[Test]
public void LuaInterfaceReferenceTypes ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
......@@ -1322,7 +1321,7 @@ public class LuaTests
lua.DoString ("function itest:test5(x,y) return x.testval+y.testval; end");
lua.DoString ("test=TestClass()");
lua.DoString ("a=test:callInterface5(itest)");
int a = (int) lua.GetNumber ("a");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (5, a);
//Console.WriteLine("interface returned: "+a);
}
......@@ -1335,7 +1334,7 @@ public class LuaTests
[Test]
public void LuaInterfaceReferenceTypesOutParam ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
......@@ -1343,7 +1342,7 @@ public class LuaTests
lua.DoString ("function itest:test6(x) return x,TestClass(x*2); end");
lua.DoString ("test=TestClass()");
lua.DoString ("a=test:callInterface6(itest)");
int a = (int) lua.GetNumber ("a");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (6, a);
//Console.WriteLine("interface returned: "+a);
}
......@@ -1356,14 +1355,14 @@ public class LuaTests
[Test]
public void LuaInterfaceReferenceTypesByRefParam ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.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");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (5, a);
//Console.WriteLine("interface returned: "+a);
}
......@@ -1390,7 +1389,7 @@ public class LuaTests
return __luaInterface_luaTable;
}
public override int overridableMethod(int x, int y)
public override int overridableMethod (int x, int y)
{
object [] args = new object [] {
__luaInterface_luaTable,
......@@ -1406,11 +1405,10 @@ public class LuaTests
Type [] returnTypes = __luaInterface_returnTypes [0];
LuaFunction function = LuaInterface.Method.LuaClassHelper.getTableFunction (__luaInterface_luaTable, "overridableMethod");
object ret = LuaInterface.Method.LuaClassHelper.callFunction (function, args, returnTypes, inArgs, outArgs);
return (int) ret;
return (int)ret;
}
}
class LuaITestClassHandler : ILuaGeneratedType, ITest
{
public LuaTable __luaInterface_luaTable;
......@@ -1427,8 +1425,7 @@ public class LuaTests
return __luaInterface_luaTable;
}
public int intProp
{
public int intProp {
get {
object [] args = new object [] { __luaInterface_luaTable };
object [] inArgs = new object [] { __luaInterface_luaTable };
......@@ -1436,11 +1433,18 @@ public class LuaTests
Type [] returnTypes = __luaInterface_returnTypes [0];
LuaFunction function = LuaInterface.Method.LuaClassHelper.getTableFunction (__luaInterface_luaTable, "get_intProp");
object ret = LuaInterface.Method.LuaClassHelper.callFunction (function, args, returnTypes, inArgs, outArgs);
return (int) ret;
} set {
return (int)ret;
}
set {
int i = value;
object [] args = new object [] { __luaInterface_luaTable , i};
object [] inArgs = new object [] { __luaInterface_luaTable, i };
object [] args = new object [] {
__luaInterface_luaTable ,
i
};
object [] inArgs = new object [] {
__luaInterface_luaTable,
i
};
int [] outArgs = new int [] { };
Type [] returnTypes = __luaInterface_returnTypes [1];
LuaFunction function = LuaInterface.Method.LuaClassHelper.getTableFunction (__luaInterface_luaTable, "set_intProp");
......@@ -1448,8 +1452,7 @@ public class LuaTests
}
}
public TestClass refProp
{
public TestClass refProp {
get {
object [] args = new object [] { __luaInterface_luaTable };
object [] inArgs = new object [] { __luaInterface_luaTable };
......@@ -1457,11 +1460,18 @@ public class LuaTests
Type [] returnTypes = __luaInterface_returnTypes [2];
LuaFunction function = LuaInterface.Method.LuaClassHelper.getTableFunction (__luaInterface_luaTable, "get_refProp");
object ret = LuaInterface.Method.LuaClassHelper.callFunction (function, args, returnTypes, inArgs, outArgs);
return (TestClass) ret;
} set {
return (TestClass)ret;
}
set {
TestClass test = value;
object [] args = new object [] { __luaInterface_luaTable , test};
object [] inArgs = new object [] { __luaInterface_luaTable, test };
object [] args = new object [] {
__luaInterface_luaTable ,
test
};
object [] inArgs = new object [] {
__luaInterface_luaTable,
test
};
int [] outArgs = new int [] { };
Type [] returnTypes = __luaInterface_returnTypes [3];
LuaFunction function = LuaInterface.Method.LuaClassHelper.getTableFunction (__luaInterface_luaTable, "set_refProp");
......@@ -1485,7 +1495,7 @@ public class LuaTests
Type [] returnTypes = __luaInterface_returnTypes [4];
LuaFunction function = LuaInterface.Method.LuaClassHelper.getTableFunction (__luaInterface_luaTable, "test1");
object ret = LuaInterface.Method.LuaClassHelper.callFunction (function, args, returnTypes, inArgs, outArgs);
return (int) ret;
return (int)ret;
}
public int test2 (int a, out int b)
......@@ -1504,7 +1514,7 @@ public class LuaTests
LuaFunction function = LuaInterface.Method.LuaClassHelper.getTableFunction (__luaInterface_luaTable, "test2");
object ret = LuaInterface.Method.LuaClassHelper.callFunction (function, args, returnTypes, inArgs, outArgs);
b = (int)args [1];
return (int) ret;
return (int)ret;
}
public void test3 (int a, ref int b)
......@@ -1542,7 +1552,7 @@ public class LuaTests
Type [] returnTypes = __luaInterface_returnTypes [7];
LuaFunction function = LuaInterface.Method.LuaClassHelper.getTableFunction (__luaInterface_luaTable, "test4");
object ret = LuaInterface.Method.LuaClassHelper.callFunction (function, args, returnTypes, inArgs, outArgs);
return (TestClass) ret;
return (TestClass)ret;
}
public int test5 (TestClass a, TestClass b)
......@@ -1561,7 +1571,7 @@ public class LuaTests
Type [] returnTypes = __luaInterface_returnTypes [8];
LuaFunction function = LuaInterface.Method.LuaClassHelper.getTableFunction (__luaInterface_luaTable, "test5");
object ret = LuaInterface.Method.LuaClassHelper.callFunction (function, args, returnTypes, inArgs, outArgs);
return (int) ret;
return (int)ret;
}
public int test6 (int a, out TestClass b)
......@@ -1581,7 +1591,7 @@ public class LuaTests
object ret = LuaInterface.Method.LuaClassHelper.callFunction (function, args, returnTypes, inArgs, outArgs);
b = (TestClass)args [1];
return (int) ret;
return (int)ret;
}
public void test7 (int a, ref TestClass b)
......@@ -1599,7 +1609,7 @@ public class LuaTests
int [] outArgs = new int [] { 1 };
Type [] returnTypes = __luaInterface_returnTypes [10];
LuaFunction function = LuaInterface.Method.LuaClassHelper.getTableFunction (__luaInterface_luaTable, "test7");
object ret = LuaInterface.Method.LuaClassHelper.callFunction (function, args, returnTypes, inArgs, outArgs);
LuaInterface.Method.LuaClassHelper.callFunction (function, args, returnTypes, inArgs, outArgs);
b = (TestClass)args [1];
}
}
......@@ -1612,7 +1622,7 @@ public class LuaTests
[Test]
public void LuaInterfaceValueProperty ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
......@@ -1620,7 +1630,7 @@ public class LuaTests
lua.DoString ("function itest:get_intProp() return itest.int_prop; end");
lua.DoString ("function itest:set_intProp(val) itest.int_prop=val; end");
lua.DoString ("a=test:callInterface8(itest)");
int a = (int) lua.GetNumber ("a");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (3, a);
//Console.WriteLine("interface returned: "+a);
}
......@@ -1632,7 +1642,7 @@ public class LuaTests
[Test]
public void LuaInterfaceReferenceProperty ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
......@@ -1640,7 +1650,7 @@ public class LuaTests
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");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (3, a);
//Console.WriteLine("interface returned: "+a);
}
......@@ -1654,15 +1664,15 @@ public class LuaTests
[Test]
public void LuaTableBaseMethod ()
{
using (Lua lua = new Lua () ) {
lua.RegisterLuaClassType (typeof (TestClass), typeof (LuaTestClassHandler));
using (Lua lua = new Lua ()) {
lua.RegisterLuaClassType (typeof(TestClass), typeof(LuaTestClassHandler));
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("test={}");
lua.DoString ("function test:overridableMethod(x,y) print(self[base]); return 6 end");
lua.DoString ("luanet.make_object(test,'LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("a=TestClass.callOverridable(test,2,3)");
int a = (int) lua.GetNumber ("a");
int a = (int)lua.GetNumber ("a");
lua.DoString ("luanet.free_object(test)");
Assert.AreEqual (6, a);
// lua.DoString("luanet.load_assembly('LuaInterfaceTest')");
......@@ -1685,15 +1695,15 @@ public class LuaTests
[Test]
public void GetMethodBySignatureFromObj ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('mscorlib')");
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
lua.DoString ("setMethod=luanet.get_method_bysig(test,'setVal','System.String')");
lua.DoString ("setMethod('test')");
TestClass test = (TestClass) lua ["test"];
Assert.AreEqual ("test", test.getStrVal () );
TestClass test = (TestClass)lua ["test"];
Assert.AreEqual ("test", test.getStrVal ());
//Console.WriteLine("interface returned: "+test.getStrVal());
}
}
......@@ -1704,15 +1714,15 @@ public class LuaTests
[Test]
public void GetMethodBySignatureFromType ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('mscorlib')");
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
lua.DoString ("setMethod=luanet.get_method_bysig(TestClass,'setVal','System.String')");
lua.DoString ("setMethod(test,'test')");
TestClass test = (TestClass) lua ["test"];
Assert.AreEqual ("test", test.getStrVal () );
TestClass test = (TestClass)lua ["test"];
Assert.AreEqual ("test", test.getStrVal ());
//Console.WriteLine("interface returned: "+test.getStrVal());
}
}
......@@ -1722,14 +1732,14 @@ public class LuaTests
[Test]
public void GetStaticMethodBySignature ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('mscorlib')");
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("make_method=luanet.get_method_bysig(TestClass,'makeFromString','System.String')");
lua.DoString ("test=make_method('test')");
TestClass test = (TestClass) lua ["test"];
Assert.AreEqual ("test", test.getStrVal () );
TestClass test = (TestClass)lua ["test"];
Assert.AreEqual ("test", test.getStrVal ());
//Console.WriteLine("interface returned: "+test.getStrVal());
}
}
......@@ -1739,17 +1749,17 @@ public class LuaTests
[Test]
public void GetConstructorBySignature ()
{
using (Lua lua = new Lua () ) {
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('mscorlib')");
lua.DoString ("luanet.load_assembly('LuaInterfaceTest')");
lua.DoString ("TestClass=luanet.import_type('LuaInterfaceTest.Mock.TestClass')");
lua.DoString ("test_cons=luanet.get_constructor_bysig(TestClass,'System.String')");
lua.DoString ("test=test_cons('test')");
TestClass test = (TestClass) lua ["test"];
Assert.AreEqual ("test", test.getStrVal () );
TestClass test = (TestClass)lua ["test"];
Assert.AreEqual ("test", test.getStrVal ());
//Console.WriteLine("interface returned: "+test.getStrVal());
}
}
}
}
}
......@@ -2,7 +2,6 @@
namespace LuaInterfaceTest.Mock
{
using System;
using LuaInterface;
using System.Threading;
......@@ -12,13 +11,19 @@ namespace LuaInterfaceTest.Mock
/*
* Delegates used for testing Lua function -> delegate translation
*/
public delegate int TestDelegate1(int a, int b);
public delegate int TestDelegate2(int a, out int b);
public delegate void TestDelegate3(int a, ref int b);
public delegate TestClass TestDelegate4(int a, int b);
public delegate int TestDelegate5(TestClass a, TestClass b);
public delegate int TestDelegate6(int a, out TestClass b);
public delegate void TestDelegate7(int a, ref TestClass b);
public delegate int TestDelegate1 (int a, int b);
public delegate int TestDelegate2 (int a, out int b);
public delegate void TestDelegate3 (int a, ref int b);
public delegate TestClass TestDelegate4 (int a, int b);
public delegate int TestDelegate5 (TestClass a, TestClass b);
public delegate int TestDelegate6 (int a, out TestClass b);
public delegate void TestDelegate7 (int a, ref TestClass b);
/* Delegate Lua-handlers */
......@@ -32,7 +37,7 @@ namespace LuaInterfaceTest.Mock
object ret = base.callFunction (args, inArgs, outArgs);
return (int) ret;
return (int)ret;
}
}
......@@ -47,7 +52,7 @@ namespace LuaInterfaceTest.Mock
object ret = base.callFunction (args, inArgs, outArgs);
b = (int)args [1];
return (int) ret;
return (int)ret;
}
}
......@@ -75,7 +80,7 @@ namespace LuaInterfaceTest.Mock
object ret = base.callFunction (args, inArgs, outArgs);
return (TestClass) ret;
return (TestClass)ret;
}
}
......@@ -89,7 +94,7 @@ namespace LuaInterfaceTest.Mock
object ret = base.callFunction (args, inArgs, outArgs);
return (int) ret;
return (int)ret;
}
}
......@@ -104,7 +109,7 @@ namespace LuaInterfaceTest.Mock
object ret = base.callFunction (args, inArgs, outArgs);
b = (TestClass)args [1];
return (int) ret;
return (int)ret;
}
}
......@@ -128,38 +133,47 @@ namespace LuaInterfaceTest.Mock
*/
public interface ITest
{
int intProp
{
int intProp {
get;
set;
}
TestClass refProp
{
TestClass refProp {
get;
set;
}
int test1(int a, int b);
int test2(int a, out int b);
void test3(int a, ref int b);
TestClass test4(int a, int b);
int test5(TestClass a, TestClass b);
int test6(int a, out TestClass b);
void test7(int a, ref TestClass b);
int test1 (int a, int b);
int test2 (int a, out int b);
void test3 (int a, ref int b);
TestClass test4 (int a, int b);
int test5 (TestClass a, TestClass b);
int test6 (int a, out TestClass b);
void test7 (int a, ref TestClass b);
}
public interface IFoo1
{
int foo();
int foo ();
}
public interface IFoo2
{
int foo();
int foo ();
}
class MyClass
{
public int Func1() { return 1; }
public int Func1 ()
{
return 1;
}
}
/// <summary>
......@@ -168,12 +182,12 @@ namespace LuaInterfaceTest.Mock
class DoWorkClass
{
public void DoWork()
public void DoWork ()
{
//simulate work by sleeping
//Console.WriteLine("Started to do work on thread: " + Thread.CurrentThread.ManagedThreadId);
Thread.Sleep(new Random().Next(0, 1000));
Thread.Sleep (new Random ().Next (0, 1000));
//Console.WriteLine("Finished work on thread: " + Thread.CurrentThread.ManagedThreadId);
}
}
......@@ -183,15 +197,14 @@ namespace LuaInterfaceTest.Mock
/// </summary>
public struct TestStruct
{
public TestStruct(float val)
public TestStruct (float val)
{
v = val;
}
public float v;
public float val
{
public float val {
get { return v; }
set { v = value; }
}
......@@ -204,28 +217,25 @@ namespace LuaInterfaceTest.Mock
public class TestClassGeneric<T>
{
private object _PassedValue;
private bool _RegularMethodSuccess;
public bool RegularMethodSuccess
{
public bool RegularMethodSuccess {
get { return _RegularMethodSuccess; }
}
private bool _GenericMethodSuccess;
public bool GenericMethodSuccess
{
public bool GenericMethodSuccess {
get { return _GenericMethodSuccess; }
}
public void GenericMethod(T value)
public void GenericMethod (T value)
{
_PassedValue = value;
_GenericMethodSuccess = true;
}
public void RegularMethod()
public void RegularMethod ()
{
_RegularMethodSuccess = true;
}
......@@ -235,9 +245,9 @@ namespace LuaInterfaceTest.Mock
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public bool Validate(T value)
public bool Validate (T value)
{
return value.Equals(_PassedValue);
return value.Equals (_PassedValue);
}
}
......@@ -248,37 +258,36 @@ namespace LuaInterfaceTest.Mock
{
private object _PassedValue;
public object PassedValue
{
public object PassedValue {
get { return _PassedValue; }
}
private bool _GenericMethodSuccess;
public bool GenericMethodSuccess
{
public bool GenericMethodSuccess {
get { return _GenericMethodSuccess; }
}
public void GenericMethod<T>(T value)
public void GenericMethod<T> (T value)
{
_PassedValue = value;
_GenericMethodSuccess = true;
}
internal bool Validate<T>(T value)
internal bool Validate<T> (T value)
{
return value.Equals(_PassedValue);
return value.Equals (_PassedValue);
}
}
public class TestClass2
{
public static int func(int x, int y)
public static int func (int x, int y)
{
return x + y;
}
public int funcInstance(int x, int y)
public int funcInstance (int x, int y)
{
return x + y;
}
......@@ -292,235 +301,260 @@ namespace LuaInterfaceTest.Mock
{
public int val;
private string strVal;
public TestClass()
public TestClass ()
{
val = 0;
}
public TestClass(int val)
public TestClass (int val)
{
this.val = val;
}
public TestClass(string val)
public TestClass (string val)
{
this.strVal = val;
}
public static TestClass makeFromString(String str)
public static TestClass makeFromString (String str)
{
return new TestClass(str);
return new TestClass (str);
}
bool? nb2 = null;
public bool? NullableBool
{
public bool? NullableBool {
get { return nb2; }
set { nb2 = value; }
}
TestStruct s = new TestStruct ();
TestStruct s = new TestStruct();
public TestStruct Struct
{
public TestStruct Struct {
get { return s; }
set { s = (TestStruct)value; }
}
public int testval
{
get
{
public int testval {
get {
return this.val;
}
set
{
set {
this.val = value;
}
}
public int this[int index]
{
public int this [int index] {
get { return 1; }
set { }
}
public int this[string index]
{
public int this [string index] {
get { return 1; }
set { }
}
public int sum(int x, int y)
public int sum (int x, int y)
{
return x + y;
}
public void setVal(int newVal)
public void setVal (int newVal)
{
val = newVal;
}
public void setVal(string newVal)
public void setVal (string newVal)
{
strVal = newVal;
}
public int getVal()
public int getVal ()
{
return val;
}
public string getStrVal()
public string getStrVal ()
{
return strVal;
}
public int outVal(out int val)
public int outVal (out int val)
{
val = 5;
return 3;
}
public int outVal(out int val, int val2)
public int outVal (out int val, int val2)
{
val = 5;
return val2;
}
public int outVal(int val, ref int val2)
public int outVal (int val, ref int val2)
{
val2 = val + val2;
return val;
}
public int outValMutiple(int arg, out string arg2, out string arg3)
public int outValMutiple (int arg, out string arg2, out string arg3)
{
arg2 = Guid.NewGuid().ToString();
arg3 = Guid.NewGuid().ToString();
arg2 = Guid.NewGuid ().ToString ();
arg3 = Guid.NewGuid ().ToString ();
return arg;
}
public int callDelegate1(TestDelegate1 del)
public int callDelegate1 (TestDelegate1 del)
{
return del(2, 3);
return del (2, 3);
}
public int callDelegate2(TestDelegate2 del)
public int callDelegate2 (TestDelegate2 del)
{
int a = 3;
int b = del(2, out a);
int b = del (2, out a);
return a + b;
}
public int callDelegate3(TestDelegate3 del)
public int callDelegate3 (TestDelegate3 del)
{
int a = 3;
del(2, ref a);
del (2, ref a);
//Console.WriteLine(a);
return a;
}
public int callDelegate4(TestDelegate4 del)
public int callDelegate4 (TestDelegate4 del)
{
return del(2, 3).testval;
return del (2, 3).testval;
}
public int callDelegate5(TestDelegate5 del)
public int callDelegate5 (TestDelegate5 del)
{
return del(new TestClass(2), new TestClass(3));
return del (new TestClass (2), new TestClass (3));
}
public int callDelegate6(TestDelegate6 del)
public int callDelegate6 (TestDelegate6 del)
{
TestClass test = new TestClass();
int a = del(2, out test);
TestClass test = new TestClass ();
int a = del (2, out test);
return a + test.testval;
}
public int callDelegate7(TestDelegate7 del)
public int callDelegate7 (TestDelegate7 del)
{
TestClass test = new TestClass(3);
del(2, ref test);
TestClass test = new TestClass (3);
del (2, ref test);
return test.testval;
}
public int callInterface1(ITest itest)
public int callInterface1 (ITest itest)
{
return itest.test1(2, 3);
return itest.test1 (2, 3);
}
public int callInterface2(ITest itest)
public int callInterface2 (ITest itest)
{
int a = 3;
int b = itest.test2(2, out a);
int b = itest.test2 (2, out a);
return a + b;
}
public int callInterface3(ITest itest)
public int callInterface3 (ITest itest)
{
int a = 3;
itest.test3(2, ref a);
itest.test3 (2, ref a);
//Console.WriteLine(a);
return a;
}
public int callInterface4(ITest itest)
public int callInterface4 (ITest itest)
{
return itest.test4(2, 3).testval;
return itest.test4 (2, 3).testval;
}
public int callInterface5(ITest itest)
public int callInterface5 (ITest itest)
{
return itest.test5(new TestClass(2), new TestClass(3));
return itest.test5 (new TestClass (2), new TestClass (3));
}
public int callInterface6(ITest itest)
public int callInterface6 (ITest itest)
{
TestClass test = new TestClass();
int a = itest.test6(2, out test);
TestClass test = new TestClass ();
int a = itest.test6 (2, out test);
return a + test.testval;
}
public int callInterface7(ITest itest)
public int callInterface7 (ITest itest)
{
TestClass test = new TestClass(3);
itest.test7(2, ref test);
TestClass test = new TestClass (3);
itest.test7 (2, ref test);
return test.testval;
}
public int callInterface8(ITest itest)
public int callInterface8 (ITest itest)
{
itest.intProp = 3;
return itest.intProp;
}
public int callInterface9(ITest itest)
public int callInterface9 (ITest itest)
{
itest.refProp = new TestClass(3);
itest.refProp = new TestClass (3);
return itest.refProp.testval;
}
public void exceptionMethod()
public void exceptionMethod ()
{
throw new Exception("exception test");
throw new Exception ("exception test");
}
public virtual int overridableMethod(int x, int y)
public virtual int overridableMethod (int x, int y)
{
return x + y;
}
public static int callOverridable(TestClass test, int x, int y)
public static int callOverridable (TestClass test, int x, int y)
{
return test.overridableMethod(x, y);
return test.overridableMethod (x, y);
}
int IFoo1.foo()
int IFoo1.foo ()
{
return 3;
}
public int foo()
public int foo ()
{
return 5;
}
private void _PrivateMethod()
private void _PrivateMethod ()
{
Console.WriteLine("Private method called");
Console.WriteLine ("Private method called");
}
public void MethodOverload()
public void MethodOverload ()
{
Console.WriteLine("Method with no params");
Console.WriteLine ("Method with no params");
}
public void MethodOverload(TestClass testClass)
public void MethodOverload (TestClass testClass)
{
Console.WriteLine("Method with testclass param");
Console.WriteLine ("Method with testclass param");
}
public void MethodOverload(int i, int j, int k)
public void MethodOverload (int i, int j, int k)
{
Console.WriteLine("Overload without out param: " + i + ", " + j + ", " + k);
Console.WriteLine ("Overload without out param: " + i + ", " + j + ", " + k);
}
public void MethodOverload(int i, int j, out int k)
public void MethodOverload (int i, int j, out int k)
{
k = 5;
Console.WriteLine("Overload with out param" + i + ", " + j);
Console.WriteLine ("Overload with out param" + i + ", " + j);
}
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment