"vscode:/vscode.git/clone" did not exist on "079b7966245cccb42c563abeb19290459e10934e"
Commit 8f41eff7 authored by Vinicius Jarina's avatar Vinicius Jarina
Browse files

Minor cleanup. (removed unnecessary attributes).

parent e029feb0
......@@ -47,13 +47,9 @@ namespace NLua
*/
sealed class CheckType
{
#if SILVERLIGHT
private Dictionary<Type, ExtractValue> extractValues = new Dictionary<Type, ExtractValue>();
#else
private Dictionary<long, ExtractValue> extractValues = new Dictionary<long, ExtractValue> ();
#endif
private ExtractValue extractNetObject;
private ObjectTranslator translator;
Dictionary<Type, ExtractValue> extractValues = new Dictionary<Type, ExtractValue>();
ExtractValue extractNetObject;
ObjectTranslator translator;
public CheckType (ObjectTranslator translator)
{
......@@ -185,17 +181,10 @@ namespace NLua
return null;
}
#if SILVERLIGHT
private Type GetExtractDictionaryKey(Type targetType)
Type GetExtractDictionaryKey(Type targetType)
{
return targetType;
}
#else
private long GetExtractDictionaryKey(Type targetType)
{
return targetType.TypeHandle.Value.ToInt64();
}
#endif
/*
* The following functions return the value in the Lua stack
......
......@@ -333,7 +333,6 @@ end
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
static int PanicCallback (LuaState luaState)
{
string reason = string.Format ("unprotected error in call to Lua API ({0})", LuaLib.LuaToString (luaState, -1));
......@@ -426,7 +425,7 @@ end
}
/// <summary>
///
/// Load a File on, and return a LuaFunction to execute the file loaded (useful to see if the syntax of a file is ok)
/// </summary>
/// <param name = "fileName"></param>
/// <returns></returns>
......@@ -603,8 +602,8 @@ end
string name = method.Name;
if (
// Check that the LuaHideAttribute and LuaGlobalAttribute were not applied
(method.GetCustomAttributes (typeof(LuaHideAttribute), false).Length == 0) &&
(method.GetCustomAttributes (typeof(LuaGlobalAttribute), false).Length == 0) &&
(!method.GetCustomAttributes (typeof(LuaHideAttribute), false).Any ()) &&
(!method.GetCustomAttributes (typeof(LuaGlobalAttribute), false).Any ()) &&
// Exclude some generic .NET methods that wouldn't be very usefull in Lua
name != "GetType" && name != "GetHashCode" && name != "Equals" &&
name != "ToString" && name != "Clone" && name != "Dispose" &&
......@@ -627,8 +626,8 @@ end
foreach (var field in type.GetFields(BindingFlags.Public | BindingFlags.Instance)) {
if (
// Check that the LuaHideAttribute and LuaGlobalAttribute were not applied
(field.GetCustomAttributes (typeof(LuaHideAttribute), false).Length == 0) &&
(field.GetCustomAttributes (typeof(LuaGlobalAttribute), false).Length == 0)) {
(!field.GetCustomAttributes (typeof(LuaHideAttribute), false).Any ()) &&
(!field.GetCustomAttributes (typeof(LuaGlobalAttribute), false).Any ())) {
// Go into recursion for members
RegisterGlobal (path + "." + field.Name, field.FieldType, recursionCounter + 1);
}
......@@ -639,8 +638,8 @@ end
foreach (var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance)) {
if (
// Check that the LuaHideAttribute and LuaGlobalAttribute were not applied
(property.GetCustomAttributes (typeof(LuaHideAttribute), false).Length == 0) &&
(property.GetCustomAttributes (typeof(LuaGlobalAttribute), false).Length == 0)
(!property.GetCustomAttributes (typeof(LuaHideAttribute), false).Any ()) &&
(!property.GetCustomAttributes (typeof(LuaGlobalAttribute), false).Any ())
// Exclude some generic .NET properties that wouldn't be very usefull in Lua
&& property.Name != "Item") {
// Go into recursion for members
......@@ -660,7 +659,7 @@ end
* Navigates a table in the top of the stack, returning
* the value of the specified field
*/
internal object GetObject (string[] remainingPath)
object GetObject (string[] remainingPath)
{
object returnValue = null;
......@@ -792,7 +791,7 @@ end
/*
* Navigates a table to set the value of one of its fields
*/
internal void SetObject (string[] remainingPath, object val)
void SetObject (string[] remainingPath, object val)
{
for (int i = 0; i < remainingPath.Length-1; i++) {
LuaLib.LuaPushString (luaState, remainingPath [i]);
......@@ -965,7 +964,6 @@ end
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaHook))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
#if USE_KOPILUA
static void DebugHookCallback (LuaState luaState, LuaDebug debug)
{
......@@ -1068,7 +1066,8 @@ end
/*
* Sets a field of the table or userdata corresponding the the provided reference
* to the provided value
*/ internal void SetObject (int reference, string field, object val)
*/
internal void SetObject (int reference, string field, object val)
{
int oldTop = LuaLib.LuaGetTop (luaState);
LuaLib.LuaGetRef (luaState, reference);
......
......@@ -126,7 +126,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int RunFunctionDelegate (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......@@ -146,7 +145,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int CollectObject (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......@@ -169,7 +167,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int ToStringLua (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......@@ -195,7 +192,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
static int AddLua (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......@@ -208,7 +204,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
static int SubtractLua (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......@@ -221,7 +216,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
static int MultiplyLua (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......@@ -234,7 +228,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
static int DivideLua (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......@@ -247,7 +240,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
static int ModLua (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......@@ -260,12 +252,12 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
static int UnaryNegationLua (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
return UnaryNegationLua (luaState, translator);
}
static int UnaryNegationLua (LuaState luaState, ObjectTranslator translator)
{
object obj1 = translator.GetRawNetObject (luaState, 1);
......@@ -296,7 +288,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
static int EqualLua (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......@@ -309,7 +300,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
static int LessThanLua (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......@@ -322,7 +312,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
static int LessThanOrEqualLua (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......@@ -376,7 +365,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int GetMethod (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......@@ -481,7 +469,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int GetBaseMethod (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......@@ -740,7 +727,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int SetFieldOrProperty (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......@@ -915,7 +901,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int GetClassMethod (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......@@ -957,7 +942,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int SetClassFieldOrProperty (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......@@ -988,7 +972,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int CallConstructor (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......@@ -1252,7 +1235,7 @@ namespace NLua
{
extractValue = null;
if (currentNetParam.GetCustomAttributes (typeof(ParamArrayAttribute), false).Length > 0) {
if (currentNetParam.GetCustomAttributes (typeof(ParamArrayAttribute), false).Any ()) {
LuaTypes luaType;
try {
......
......@@ -262,7 +262,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int LoadAssembly (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......@@ -346,7 +345,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int ImportType (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......@@ -374,7 +372,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int RegisterTable (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......@@ -426,7 +423,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int UnregisterTable (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......@@ -471,7 +467,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int GetMethodSignature (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......@@ -524,7 +519,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int GetConstructorSignature (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......@@ -974,7 +968,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int CType (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......@@ -994,7 +987,6 @@ namespace NLua
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int EnumFromInt (LuaState luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
......
......@@ -24,66 +24,66 @@ namespace NLuaTest
#if MONOTOUCH
[Preserve (AllMembers = true)]
#endif
public class TestCaseName {
public string name = "name";
public string Name {
get {
return "**" + name + "**";
}
}
}
#endif
public class TestCaseName {
public string name = "name";
public string Name {
get {
return "**" + name + "**";
}
}
}
#if MONOTOUCH
[Preserve (AllMembers = true)]
#endif
public class Vector
{
public double x;
public double y;
public static Vector operator * (float k, Vector v)
{
var r = new Vector ();
r.x = v.x * k;
r.y = v.y * k;
return r;
}
public static Vector operator * (Vector v, float k)
{
var r = new Vector ();
r.x = v.x * k;
r.y = v.y * k;
return r;
}
public void Func ()
{
Console.WriteLine ("Func");
}
}
public static class VectorExtension
{
public static double Lenght (this Vector v)
{
return v.x * v.x + v.y * v.y;
}
}
#endif
public class Vector
{
public double x;
public double y;
public static Vector operator * (float k, Vector v)
{
var r = new Vector ();
r.x = v.x * k;
r.y = v.y * k;
return r;
}
public static Vector operator * (Vector v, float k)
{
var r = new Vector ();
r.x = v.x * k;
r.y = v.y * k;
return r;
}
public void Func ()
{
Console.WriteLine ("Func");
}
}
public static class VectorExtension
{
public static double Lenght (this Vector v)
{
return v.x * v.x + v.y * v.y;
}
}
[TestFixture]
#if MONOTOUCH
[Preserve (AllMembers = true)]
#endif
public class LuaTests
{
public static readonly char UnicodeChar = '\uE007';
public static string UnicodeString
{
get
{
return Convert.ToString (UnicodeChar);
}
{
public static readonly char UnicodeChar = '\uE007';
public static string UnicodeString
{
get
{
return Convert.ToString (UnicodeChar);
}
}
/*
* Tests capturing an exception
......@@ -165,20 +165,20 @@ namespace NLuaTest
lua.DoString ("val=test.Struct.val");
Assert.AreEqual (2.0d, (double)lua ["val"]);
}
}
[Test]
public void TestStructHashesEqual()
{
using (Lua lua = new Lua())
{
lua.DoString("luanet.load_assembly('NLuaTest')");
lua.DoString("TestStruct=luanet.import_type('NLuaTest.Mock.TestStruct')");
lua.DoString("struct1=TestStruct(0)");
lua.DoString("struct2=TestStruct(0)");
lua.DoString("struct2.val=1");
Assert.AreEqual(0, (double)lua["struct1.val"]);
}
}
[Test]
public void TestStructHashesEqual()
{
using (Lua lua = new Lua())
{
lua.DoString("luanet.load_assembly('NLuaTest')");
lua.DoString("TestStruct=luanet.import_type('NLuaTest.Mock.TestStruct')");
lua.DoString("struct1=TestStruct(0)");
lua.DoString("struct2=TestStruct(0)");
lua.DoString("struct2.val=1");
Assert.AreEqual(0, (double)lua["struct1.val"]);
}
}
[Test]
......@@ -1887,17 +1887,17 @@ namespace NLuaTest
lua.DoString ("test:Print('this will pass')");
lua.DoString ("test:Print('this will ','fail')");
}
}
[Test]
public void TestCtype ()
{
using (Lua lua = new Lua ()) {
}
[Test]
public void TestCtype ()
{
using (Lua lua = new Lua ()) {
lua.LoadCLRPackage ();
lua.DoString ("import'System'");
lua.DoString ("import'System'");
var x = lua.DoString ("return luanet.ctype(String)")[0];
Assert.AreEqual (x, typeof(String), "#1 String ctype test");
}
Assert.AreEqual (x, typeof(String), "#1 String ctype test");
}
}
[Test]
......@@ -1910,298 +1910,298 @@ namespace NLuaTest
}
[Test]
public void TestUnicodeChars ()
{
using (Lua lua = new Lua ()) {
lua.LoadCLRPackage ();
lua.DoString ("import('NLuaTest')");
lua.DoString ("res = LuaTests.UnicodeString");
string res = (string)lua ["res"];
Assert.AreEqual (LuaTests.UnicodeString, res);
}
}
[Test]
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);
}
}
[Test]
public void TestDebugHook ()
{
int [] lines = { 1, 2, 1, 3 };
int line = 0;
using (Lua lua = new Lua ()) {
lua.DebugHook += (sender,args) => {
Assert.AreEqual (args.LuaDebug.currentline,lines [line]);
line ++;
};
lua.SetDebugHook (NLua.Event.EventMasks.LUA_MASKLINE, 0);
lua.DoString (@"function testing_hooks() return 10 end
val = testing_hooks()
val = val + 1");
}
}
[Test]
public void TestKeyWithDots ()
{
using (Lua lua = new Lua ()) {
lua.DoString (@"g_dot = {}
g_dot['key.with.dot'] = 42");
Assert.AreEqual (42, (int)(double)lua ["g_dot.key\\.with\\.dot"]);
}
public void TestUnicodeChars ()
{
using (Lua lua = new Lua ()) {
lua.LoadCLRPackage ();
lua.DoString ("import('NLuaTest')");
lua.DoString ("res = LuaTests.UnicodeString");
string res = (string)lua ["res"];
Assert.AreEqual (LuaTests.UnicodeString, res);
}
}
[Test]
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);
}
}
[Test]
public void TestDebugHook ()
{
int [] lines = { 1, 2, 1, 3 };
int line = 0;
using (Lua lua = new Lua ()) {
lua.DebugHook += (sender,args) => {
Assert.AreEqual (args.LuaDebug.currentline,lines [line]);
line ++;
};
lua.SetDebugHook (NLua.Event.EventMasks.LUA_MASKLINE, 0);
lua.DoString (@"function testing_hooks() return 10 end
val = testing_hooks()
val = val + 1");
}
}
[Test]
public void TestKeyWithDots ()
{
using (Lua lua = new Lua ()) {
lua.DoString (@"g_dot = {}
g_dot['key.with.dot'] = 42");
Assert.AreEqual (42, (int)(double)lua ["g_dot.key\\.with\\.dot"]);
}
}
#if !WINDOWS_PHONE && !NET_3_5
[Test]
public void TestOperatorAdd ()
{
using (Lua lua = new Lua ()) {
var a = new System.Numerics.Complex (10, 0);
var b = new System.Numerics.Complex (0, 3);
var x = a + b;
lua ["a"] = a;
lua ["b"] = b;
var res = lua.DoString (@"return a + b") [0];
Assert.AreEqual (x, res);
}
}
[Test]
public void TestOperatorMinus ()
{
using (Lua lua = new Lua ()) {
var a = new System.Numerics.Complex (10, 0);
var b = new System.Numerics.Complex (0, 3);
var x = a - b;
lua ["a"] = a;
lua ["b"] = b;
var res = lua.DoString (@"return a - b") [0];
Assert.AreEqual (x, res);
}
}
[Test]
public void TestOperatorMultiply ()
{
using (Lua lua = new Lua ()) {
var a = new System.Numerics.Complex (10, 0);
var b = new System.Numerics.Complex (0, 3);
var x = a * b;
lua ["a"] = a;
lua ["b"] = b;
var res = lua.DoString (@"return a * b") [0];
Assert.AreEqual (x, res);
}
}
[Test]
public void TestOperatorEqual ()
{
using (Lua lua = new Lua ()) {
var a = new System.Numerics.Complex (10, 0);
var b = new System.Numerics.Complex (0, 3);
var x = a == b;
lua ["a"] = a;
lua ["b"] = b;
var res = lua.DoString (@"return a == b") [0];
Assert.AreEqual (x, res);
}
}
[Test]
public void TestOperatorNotEqual ()
{
using (Lua lua = new Lua ()) {
var a = new System.Numerics.Complex (10, 0);
var b = new System.Numerics.Complex (0, 3);
var x = a != b;
lua ["a"] = a;
lua ["b"] = b;
var res = lua.DoString (@"return a ~= b") [0];
Assert.AreEqual (x, res);
}
}
[Test]
public void TestUnaryMinus ()
{
using (Lua lua = new Lua ()) {
lua.LoadCLRPackage ();
lua.DoString (@" import ('System.Numerics')
c = Complex (10, 5)
c = -c ");
var expected = new System.Numerics.Complex (-10, -5);
var res = lua ["c"];
Assert.AreEqual (expected, res);
}
public void TestOperatorAdd ()
{
using (Lua lua = new Lua ()) {
var a = new System.Numerics.Complex (10, 0);
var b = new System.Numerics.Complex (0, 3);
var x = a + b;
lua ["a"] = a;
lua ["b"] = b;
var res = lua.DoString (@"return a + b") [0];
Assert.AreEqual (x, res);
}
}
[Test]
public void TestOperatorMinus ()
{
using (Lua lua = new Lua ()) {
var a = new System.Numerics.Complex (10, 0);
var b = new System.Numerics.Complex (0, 3);
var x = a - b;
lua ["a"] = a;
lua ["b"] = b;
var res = lua.DoString (@"return a - b") [0];
Assert.AreEqual (x, res);
}
}
[Test]
public void TestOperatorMultiply ()
{
using (Lua lua = new Lua ()) {
var a = new System.Numerics.Complex (10, 0);
var b = new System.Numerics.Complex (0, 3);
var x = a * b;
lua ["a"] = a;
lua ["b"] = b;
var res = lua.DoString (@"return a * b") [0];
Assert.AreEqual (x, res);
}
}
[Test]
public void TestOperatorEqual ()
{
using (Lua lua = new Lua ()) {
var a = new System.Numerics.Complex (10, 0);
var b = new System.Numerics.Complex (0, 3);
var x = a == b;
lua ["a"] = a;
lua ["b"] = b;
var res = lua.DoString (@"return a == b") [0];
Assert.AreEqual (x, res);
}
}
[Test]
public void TestOperatorNotEqual ()
{
using (Lua lua = new Lua ()) {
var a = new System.Numerics.Complex (10, 0);
var b = new System.Numerics.Complex (0, 3);
var x = a != b;
lua ["a"] = a;
lua ["b"] = b;
var res = lua.DoString (@"return a ~= b") [0];
Assert.AreEqual (x, res);
}
}
[Test]
public void TestUnaryMinus ()
{
using (Lua lua = new Lua ()) {
lua.LoadCLRPackage ();
lua.DoString (@" import ('System.Numerics')
c = Complex (10, 5)
c = -c ");
var expected = new System.Numerics.Complex (-10, -5);
var res = lua ["c"];
Assert.AreEqual (expected, res);
}
}
#endif
[Test]
public void TestCaseFields ()
{
using (Lua lua = new Lua ()) {
lua.LoadCLRPackage ();
lua.DoString (@" import ('NLuaTest')
x = TestCaseName()
name = x.name;
name2 = x.Name;
Name = x.Name;
Name2 = x.name");
Assert.AreEqual ("name", lua ["name"]);
Assert.AreEqual ("**name**", lua ["name2"]);
Assert.AreEqual ("**name**", lua ["Name"]);
Assert.AreEqual ("name", lua ["Name2"]);
}
}
[Test]
public void TestStaticOperators ()
{
using (Lua lua = new Lua ()) {
lua.LoadCLRPackage ();
lua.DoString (@" import ('NLuaTest')
v = Vector()
v.x = 10
v.y = 3
v = v*2 ");
var v = (Vector)lua ["v"];
Assert.AreEqual (20, v.x, "#1");
Assert.AreEqual (6, v.y, "#2");
lua.DoString (@" x = 2 * v");
var x = (Vector)lua ["x"];
Assert.AreEqual (40, x.x, "#3");
Assert.AreEqual (12, x.y, "#4");
}
}
[Test]
public void TestExtensionMethods ()
{
using (Lua lua = new Lua ()) {
lua.LoadCLRPackage ();
lua.DoString (@" import ('NLuaTest')
v = Vector()
v.x = 10
v.y = 3
v = v*2 ");
var v = (Vector)lua ["v"];
double len = v.Lenght ();
lua.DoString (" v:Lenght() ");
lua.DoString (@" len2 = v:Lenght()");
double len2 = (double)lua ["len2"];
Assert.AreEqual (len, len2, "#1");
}
}
[Test]
public void TestOverloadedMethods ()
{
using (Lua lua = new Lua ()) {
var obj = new TestClassWithOverloadedMethod ();
lua ["obj"] = obj;
lua.DoString (@"
obj:Func (10)
obj:Func ('10')
obj:Func (10)
obj:Func ('10')
obj:Func (10)
");
Assert.AreEqual (3, obj.CallsToIntFunc,"#integer");
Assert.AreEqual (2, obj.CallsToStringFunc, "#string");
}
}
[Test]
public void TestGetStack ()
{
using (Lua lua = new Lua ()) {
lua.LoadCLRPackage ();
m_lua = lua;
lua.DoString (@"
import ('NLuaTest')
function f1 ()
f2 ()
end
function f2()
f3()
end
function f3()
LuaTests.func()
end
f1 ()
");
}
m_lua = null;
}
public static void func()
{
#if USE_KOPILUA
string expected = "[0] [C]:-1 -- func [field]\n[1] [string \"chunk\"]:12 -- f3 [global]\n[2] [string \"chunk\"]:8 -- f2 [global]\n[3] [string \"chunk\"]:4 -- f1 [global]\n[4] [string \"chunk\"]:15 -- <unknow> []\n";
KopiLua.LuaDebug info = new KopiLua.LuaDebug ();
#else
string expected = "[0] func:-1 -- <unknown> [func]\n[1] f3:12 -- <unknown> [f3]\n[2] f2:8 -- <unknown> [f2]\n[3] f1:4 -- <unknown> [f1]\n[4] :15 -- []\n";
KeraLua.LuaDebug info = new KeraLua.LuaDebug ();
#endif
int level = 0;
StringBuilder sb = new StringBuilder ();
while (m_lua.GetStack (level,ref info) != 0) {
m_lua.GetInfo ("nSl", ref info);
string name = "<unknow>";
if (info.name != null && !string.IsNullOrEmpty(info.name.ToString()))
name = info.name.ToString ();
sb.AppendFormat ("[{0}] {1}:{2} -- {3} [{4}]\n",
level, info.shortsrc, info.currentline,
name, info.namewhat);
++level;
}
string x = sb.ToString ();
Assert.True (!string.IsNullOrEmpty(x));
}
public void TestCaseFields ()
{
using (Lua lua = new Lua ()) {
lua.LoadCLRPackage ();
lua.DoString (@" import ('NLuaTest')
x = TestCaseName()
name = x.name;
name2 = x.Name;
Name = x.Name;
Name2 = x.name");
Assert.AreEqual ("name", lua ["name"]);
Assert.AreEqual ("**name**", lua ["name2"]);
Assert.AreEqual ("**name**", lua ["Name"]);
Assert.AreEqual ("name", lua ["Name2"]);
}
}
[Test]
public void TestStaticOperators ()
{
using (Lua lua = new Lua ()) {
lua.LoadCLRPackage ();
lua.DoString (@" import ('NLuaTest')
v = Vector()
v.x = 10
v.y = 3
v = v*2 ");
var v = (Vector)lua ["v"];
Assert.AreEqual (20, v.x, "#1");
Assert.AreEqual (6, v.y, "#2");
lua.DoString (@" x = 2 * v");
var x = (Vector)lua ["x"];
Assert.AreEqual (40, x.x, "#3");
Assert.AreEqual (12, x.y, "#4");
}
}
[Test]
public void TestExtensionMethods ()
{
using (Lua lua = new Lua ()) {
lua.LoadCLRPackage ();
lua.DoString (@" import ('NLuaTest')
v = Vector()
v.x = 10
v.y = 3
v = v*2 ");
var v = (Vector)lua ["v"];
double len = v.Lenght ();
lua.DoString (" v:Lenght() ");
lua.DoString (@" len2 = v:Lenght()");
double len2 = (double)lua ["len2"];
Assert.AreEqual (len, len2, "#1");
}
}
[Test]
public void TestOverloadedMethods ()
{
using (Lua lua = new Lua ()) {
var obj = new TestClassWithOverloadedMethod ();
lua ["obj"] = obj;
lua.DoString (@"
obj:Func (10)
obj:Func ('10')
obj:Func (10)
obj:Func ('10')
obj:Func (10)
");
Assert.AreEqual (3, obj.CallsToIntFunc,"#integer");
Assert.AreEqual (2, obj.CallsToStringFunc, "#string");
}
}
[Test]
public void TestGetStack ()
{
using (Lua lua = new Lua ()) {
lua.LoadCLRPackage ();
m_lua = lua;
lua.DoString (@"
import ('NLuaTest')
function f1 ()
f2 ()
end
function f2()
f3()
end
function f3()
LuaTests.func()
end
f1 ()
");
}
m_lua = null;
}
public static void func()
{
#if USE_KOPILUA
string expected = "[0] [C]:-1 -- func [field]\n[1] [string \"chunk\"]:12 -- f3 [global]\n[2] [string \"chunk\"]:8 -- f2 [global]\n[3] [string \"chunk\"]:4 -- f1 [global]\n[4] [string \"chunk\"]:15 -- <unknow> []\n";
KopiLua.LuaDebug info = new KopiLua.LuaDebug ();
#else
//string expected = "[0] func:-1 -- <unknown> [func]\n[1] f3:12 -- <unknown> [f3]\n[2] f2:8 -- <unknown> [f2]\n[3] f1:4 -- <unknown> [f1]\n[4] :15 -- []\n";
KeraLua.LuaDebug info = new KeraLua.LuaDebug ();
#endif
int level = 0;
StringBuilder sb = new StringBuilder ();
while (m_lua.GetStack (level,ref info) != 0) {
m_lua.GetInfo ("nSl", ref info);
string name = "<unknow>";
if (info.name != null && !string.IsNullOrEmpty(info.name.ToString()))
name = info.name.ToString ();
sb.AppendFormat ("[{0}] {1}:{2} -- {3} [{4}]\n",
level, info.shortsrc, info.currentline,
name, info.namewhat);
++level;
}
string x = sb.ToString ();
Assert.True (!string.IsNullOrEmpty(x));
}
static Lua m_lua;
}
......
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