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