Commit 91321617 authored by Vinicius Jarina's avatar Vinicius Jarina
Browse files

Fixed more gendarme warnings.

parent 5866945e
...@@ -106,7 +106,7 @@ namespace NLua ...@@ -106,7 +106,7 @@ namespace NLua
var underlyingType = Nullable.GetUnderlyingType (paramType); var underlyingType = Nullable.GetUnderlyingType (paramType);
if (!underlyingType.IsNull ()) if (underlyingType != null)
paramType = underlyingType; // Silently convert nullable types to their non null requics paramType = underlyingType; // Silently convert nullable types to their non null requics
var extractKey = GetExtractDictionaryKey (paramType); var extractKey = GetExtractDictionaryKey (paramType);
...@@ -161,13 +161,13 @@ namespace NLua ...@@ -161,13 +161,13 @@ namespace NLua
if (LuaLib.LuaLGetMetafield (luaState, stackPos, "__index")) { if (LuaLib.LuaLGetMetafield (luaState, stackPos, "__index")) {
object obj = translator.GetNetObject (luaState, -1); object obj = translator.GetNetObject (luaState, -1);
LuaLib.LuaSetTop (luaState, -2); LuaLib.LuaSetTop (luaState, -2);
if (!obj.IsNull () && paramType.IsAssignableFrom (obj.GetType ())) if (obj != null && paramType.IsAssignableFrom (obj.GetType ()))
return extractNetObject; return extractNetObject;
} else } else
return null; return null;
} else { } else {
object obj = translator.GetNetObject (luaState, stackPos); object obj = translator.GetNetObject (luaState, stackPos);
if (!obj.IsNull () && paramType.IsAssignableFrom (obj.GetType ())) if (obj != null && paramType.IsAssignableFrom (obj.GetType ()))
return extractNetObject; return extractNetObject;
} }
...@@ -348,7 +348,7 @@ namespace NLua ...@@ -348,7 +348,7 @@ namespace NLua
{ {
object obj = translator.GetNetObject (luaState, stackPos); object obj = translator.GetNetObject (luaState, stackPos);
if (obj.IsNull () && LuaLib.LuaType (luaState, stackPos) == LuaTypes.Table) { if (obj == null && LuaLib.LuaType (luaState, stackPos) == LuaTypes.Table) {
if (LuaLib.LuaLGetMetafield (luaState, stackPos, "__index")) { if (LuaLib.LuaLGetMetafield (luaState, stackPos, "__index")) {
if (LuaLib.LuaLCheckMetatable (luaState, -1)) { if (LuaLib.LuaLCheckMetatable (luaState, -1)) {
LuaLib.LuaInsert (luaState, stackPos); LuaLib.LuaInsert (luaState, stackPos);
......
...@@ -30,6 +30,8 @@ namespace NLua.Exceptions ...@@ -30,6 +30,8 @@ namespace NLua.Exceptions
/// <summary> /// <summary>
/// Exceptions thrown by the Lua runtime because of errors in the script /// Exceptions thrown by the Lua runtime because of errors in the script
/// </summary> /// </summary>
///
[Serializable]
public class LuaScriptException : LuaException public class LuaScriptException : LuaException
{ {
/// <summary> /// <summary>
......
...@@ -29,7 +29,7 @@ namespace NLua.Extensions ...@@ -29,7 +29,7 @@ namespace NLua.Extensions
/// <summary> /// <summary>
/// Some random extension stuff. /// Some random extension stuff.
/// </summary> /// </summary>
static class GeneralExtensions static class CheckNull
{ {
/// <summary> /// <summary>
/// Determines whether the specified obj is null. /// Determines whether the specified obj is null.
...@@ -38,14 +38,18 @@ namespace NLua.Extensions ...@@ -38,14 +38,18 @@ namespace NLua.Extensions
/// <returns> /// <returns>
/// <c>true</c> if the specified obj is null; otherwise, <c>false</c>. /// <c>true</c> if the specified obj is null; otherwise, <c>false</c>.
/// </returns> /// </returns>
public static bool IsNull (this object obj) ///
#if USE_KOPILUA
public static bool IsNull (object obj)
{ {
return (obj == null); return (obj == null);
} }
#else
public static bool IsNull (this IntPtr ptr) public static bool IsNull (IntPtr ptr)
{ {
return (ptr.Equals (IntPtr.Zero)); return (ptr.Equals (IntPtr.Zero));
} }
#endif
} }
} }
\ No newline at end of file
...@@ -96,7 +96,7 @@ namespace NLua ...@@ -96,7 +96,7 @@ namespace NLua
#else #else
string typeName; string typeName;
lock (this) { lock (this) {
typeName = "LuaGeneratedClass" + luaClassNumber; typeName = "LuaGeneratedClass" + luaClassNumber.ToString ();
luaClassNumber++; luaClassNumber++;
} }
...@@ -138,7 +138,7 @@ namespace NLua ...@@ -138,7 +138,7 @@ namespace NLua
#else #else
string typeName; string typeName;
lock (this) { lock (this) {
typeName = "LuaGeneratedClass" + luaClassNumber; typeName = "LuaGeneratedClass" + luaClassNumber.ToString ();
luaClassNumber++; luaClassNumber++;
} }
...@@ -319,7 +319,7 @@ namespace NLua ...@@ -319,7 +319,7 @@ namespace NLua
#else #else
string typeName; string typeName;
lock (this) { lock (this) {
typeName = "LuaGeneratedClass" + luaClassNumber; typeName = "LuaGeneratedClass" + luaClassNumber.ToString ();
luaClassNumber++; luaClassNumber++;
} }
......
...@@ -324,7 +324,7 @@ end ...@@ -324,7 +324,7 @@ end
if (_StatePassed) if (_StatePassed)
return; return;
if (!luaState.IsNull ()) { if (! CheckNull.IsNull(luaState)) {
LuaCore.LuaClose (luaState); LuaCore.LuaClose (luaState);
ObjectTranslatorPool.Instance.Remove (luaState); ObjectTranslatorPool.Instance.Remove (luaState);
} }
...@@ -352,11 +352,11 @@ end ...@@ -352,11 +352,11 @@ end
// A pre-wrapped exception - just rethrow it (stack trace of InnerException will be preserved) // A pre-wrapped exception - just rethrow it (stack trace of InnerException will be preserved)
var luaEx = err as LuaScriptException; var luaEx = err as LuaScriptException;
if (!luaEx.IsNull ()) if (luaEx != null)
throw luaEx; throw luaEx;
// A non-wrapped Lua error (best interpreted as a string) - wrap it and throw it // A non-wrapped Lua error (best interpreted as a string) - wrap it and throw it
if (err.IsNull ()) if (err == null)
err = "Unknown Lua Error"; err = "Unknown Lua Error";
throw new LuaScriptException (err.ToString (), string.Empty); throw new LuaScriptException (err.ToString (), string.Empty);
...@@ -371,7 +371,7 @@ end ...@@ -371,7 +371,7 @@ end
{ {
var caughtExcept = e; var caughtExcept = e;
if (!caughtExcept.IsNull ()) { if (caughtExcept != null) {
translator.ThrowError (luaState, caughtExcept); translator.ThrowError (luaState, caughtExcept);
LuaLib.LuaPushNil (luaState); LuaLib.LuaPushNil (luaState);
return 1; return 1;
...@@ -568,7 +568,7 @@ end ...@@ -568,7 +568,7 @@ end
LuaLib.LuaSetTop (luaState, oldTop); LuaLib.LuaSetTop (luaState, oldTop);
// Globals auto-complete // Globals auto-complete
if (value.IsNull ()) { if (value == null) {
// Remove now obsolete entries // Remove now obsolete entries
globals.Remove (fullPath); globals.Remove (fullPath);
} else { } else {
...@@ -597,20 +597,21 @@ end ...@@ -597,20 +597,21 @@ end
else if ((type.IsClass || type.IsInterface) && type != typeof(string) && recursionCounter < 2) { else if ((type.IsClass || type.IsInterface) && type != typeof(string) && recursionCounter < 2) {
#region Methods #region Methods
foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Instance)) { foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Instance)) {
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).Length == 0) &&
(method.GetCustomAttributes (typeof(LuaGlobalAttribute), false).Length == 0) && (method.GetCustomAttributes (typeof(LuaGlobalAttribute), false).Length == 0) &&
// 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
method.Name != "GetType" && method.Name != "GetHashCode" && method.Name != "Equals" && name != "GetType" && name != "GetHashCode" && name != "Equals" &&
method.Name != "ToString" && method.Name != "Clone" && method.Name != "Dispose" && name != "ToString" && name != "Clone" && name != "Dispose" &&
method.Name != "GetEnumerator" && method.Name != "CopyTo" && name != "GetEnumerator" && name != "CopyTo" &&
!method.Name.StartsWith ("get_", StringComparison.Ordinal) && !name.StartsWith ("get_", StringComparison.Ordinal) &&
!method.Name.StartsWith ("set_", StringComparison.Ordinal) && !name.StartsWith ("set_", StringComparison.Ordinal) &&
!method.Name.StartsWith ("add_", StringComparison.Ordinal) && !name.StartsWith ("add_", StringComparison.Ordinal) &&
!method.Name.StartsWith ("remove_", StringComparison.Ordinal)) { !name.StartsWith ("remove_", StringComparison.Ordinal)) {
// Format for easy method invocation // Format for easy method invocation
string command = path + ":" + method.Name + "("; string command = path + ":" + name + "(";
if (method.GetParameters ().Length == 0) if (method.GetParameters ().Length == 0)
command += ")"; command += ")";
...@@ -665,7 +666,7 @@ end ...@@ -665,7 +666,7 @@ end
LuaLib.LuaGetTable (luaState, -2); LuaLib.LuaGetTable (luaState, -2);
returnValue = translator.GetObject (luaState, -1); returnValue = translator.GetObject (luaState, -1);
if (returnValue.IsNull ()) if (returnValue == null)
break; break;
} }
...@@ -765,7 +766,7 @@ end ...@@ -765,7 +766,7 @@ end
translator.Push (luaState, function); translator.Push (luaState, function);
if (!args.IsNull ()) { if (args != null) {
nArgs = args.Length; nArgs = args.Length;
for (int i = 0; i < args.Length; i++) for (int i = 0; i < args.Length; i++)
...@@ -782,7 +783,7 @@ end ...@@ -782,7 +783,7 @@ end
executing = false; executing = false;
} }
return !returnTypes.IsNull () ? translator.PopValues (luaState, oldTop, returnTypes) : translator.PopValues (luaState, oldTop); return returnTypes != null ? translator.PopValues (luaState, oldTop, returnTypes) : translator.PopValues (luaState, oldTop);
} }
/* /*
...@@ -858,7 +859,7 @@ end ...@@ -858,7 +859,7 @@ end
/// <author>Reinhard Ostermeier</author> /// <author>Reinhard Ostermeier</author>
public int SetDebugHook (EventMasks mask, int count) public int SetDebugHook (EventMasks mask, int count)
{ {
if (hookCallback.IsNull ()) { if (hookCallback == null) {
hookCallback = new LuaHook (Lua.DebugHookCallback); hookCallback = new LuaHook (Lua.DebugHookCallback);
return LuaCore.LuaSetHook (luaState, hookCallback, (int)mask, count); return LuaCore.LuaSetHook (luaState, hookCallback, (int)mask, count);
} }
...@@ -1014,7 +1015,7 @@ end ...@@ -1014,7 +1015,7 @@ end
try { try {
var temp = DebugHook; var temp = DebugHook;
if (!temp.IsNull ()) if (temp != null)
temp (this, new DebugHookEventArgs (luaDebug)); temp (this, new DebugHookEventArgs (luaDebug));
} catch (Exception ex) { } catch (Exception ex) {
OnHookException (new HookExceptionEventArgs (ex)); OnHookException (new HookExceptionEventArgs (ex));
...@@ -1024,7 +1025,7 @@ end ...@@ -1024,7 +1025,7 @@ end
private void OnHookException (HookExceptionEventArgs e) private void OnHookException (HookExceptionEventArgs e)
{ {
var temp = HookException; var temp = HookException;
if (!temp.IsNull ()) if (temp != null)
temp (this, e); temp (this, e);
} }
...@@ -1052,7 +1053,7 @@ end ...@@ -1052,7 +1053,7 @@ end
internal void DisposeInternal (int reference) internal void DisposeInternal (int reference)
{ {
if (!luaState.IsNull ()) //Fix submitted by Qingrui Li if (! CheckNull.IsNull(luaState)) //Fix submitted by Qingrui Li
LuaLib.LuaUnref (luaState, reference); LuaLib.LuaUnref (luaState, reference);
} }
...@@ -1166,13 +1167,12 @@ end ...@@ -1166,13 +1167,12 @@ end
#region IDisposable Members #region IDisposable Members
public virtual void Dispose () public virtual void Dispose ()
{ {
if (!translator.IsNull ()) { if (translator != null) {
translator.pendingEvents.Dispose (); translator.pendingEvents.Dispose ();
translator = null; translator = null;
} }
this.Close (); Close ();
GC.Collect ();
GC.WaitForPendingFinalizers (); GC.WaitForPendingFinalizers ();
} }
#endregion #endregion
......
...@@ -44,10 +44,10 @@ namespace NLua ...@@ -44,10 +44,10 @@ namespace NLua
public static void TaggedInstanceMethods (Lua lua, object o) public static void TaggedInstanceMethods (Lua lua, object o)
{ {
#region Sanity checks #region Sanity checks
if (lua.IsNull ()) if (lua == null)
throw new ArgumentNullException ("lua"); throw new ArgumentNullException ("lua");
if (o.IsNull ()) if (o == null)
throw new ArgumentNullException ("o"); throw new ArgumentNullException ("o");
#endregion #endregion
...@@ -71,10 +71,10 @@ namespace NLua ...@@ -71,10 +71,10 @@ namespace NLua
public static void TaggedStaticMethods (Lua lua, Type type) public static void TaggedStaticMethods (Lua lua, Type type)
{ {
#region Sanity checks #region Sanity checks
if (lua.IsNull ()) if (lua == null)
throw new ArgumentNullException ("lua"); throw new ArgumentNullException ("lua");
if (type.IsNull ()) if (type == null)
throw new ArgumentNullException ("type"); throw new ArgumentNullException ("type");
if (!type.IsClass) if (!type.IsClass)
...@@ -102,7 +102,7 @@ namespace NLua ...@@ -102,7 +102,7 @@ namespace NLua
public static void Enumeration<T> (Lua lua) public static void Enumeration<T> (Lua lua)
{ {
#region Sanity checks #region Sanity checks
if (lua.IsNull ()) if (lua == null)
throw new ArgumentNullException ("lua"); throw new ArgumentNullException ("lua");
#endregion #endregion
......
...@@ -100,16 +100,6 @@ namespace NLua ...@@ -100,16 +100,6 @@ namespace NLua
return _Interpreter.RawGetObject (_Reference, field); return _Interpreter.RawGetObject (_Reference, field);
} }
internal object RawGetFunction (string field)
{
object obj = _Interpreter.RawGetObject (_Reference, field);
if (obj is LuaNativeFunction)
return new LuaFunction ((LuaNativeFunction)obj, _Interpreter);
else
return obj;
}
/* /*
* Pushes this table into the Lua stack * Pushes this table into the Lua stack
*/ */
......
...@@ -78,13 +78,6 @@ namespace NLua ...@@ -78,13 +78,6 @@ namespace NLua
return _Interpreter.CallFunction (this, args); return _Interpreter.CallFunction (this, args);
} }
/*
* Pushes the userdata into the Lua stack
*/
internal void Push (LuaState luaState)
{
LuaLib.LuaGetRef (luaState, _Reference);
}
public override string ToString () public override string ToString ()
{ {
......
...@@ -152,8 +152,8 @@ namespace NLua ...@@ -152,8 +152,8 @@ namespace NLua
{ {
object obj = translator.GetRawNetObject (luaState, 1); object obj = translator.GetRawNetObject (luaState, 1);
if (!obj.IsNull ()) if (obj != null)
translator.Push (luaState, obj.ToString () + ": " + obj.GetHashCode ()); translator.Push (luaState, obj.ToString () + ": " + obj.GetHashCode ().ToString());
else else
LuaLib.LuaPushNil (luaState); LuaLib.LuaPushNil (luaState);
...@@ -168,7 +168,12 @@ namespace NLua ...@@ -168,7 +168,12 @@ namespace NLua
public static void DumpStack (ObjectTranslator translator, LuaState luaState) public static void DumpStack (ObjectTranslator translator, LuaState luaState)
{ {
int depth = LuaLib.LuaGetTop (luaState); int depth = LuaLib.LuaGetTop (luaState);
Debug.WriteLine ("lua stack depth: " + depth);
#if WINDOWS_PHONE
Debug.WriteLine("lua stack depth: {0}", depth);
#elif !SILVERLIGHT
Debug.Print ("lua stack depth: {0}", depth);
#endif
for (int i = 1; i <= depth; i++) { for (int i = 1; i <= depth; i++) {
var type = LuaLib.LuaType (luaState, i); var type = LuaLib.LuaType (luaState, i);
...@@ -211,7 +216,7 @@ namespace NLua ...@@ -211,7 +216,7 @@ namespace NLua
{ {
object obj = translator.GetRawNetObject (luaState, 1); object obj = translator.GetRawNetObject (luaState, 1);
if (obj.IsNull ()) { if (obj == null) {
translator.ThrowError (luaState, "trying to index an invalid object reference"); translator.ThrowError (luaState, "trying to index an invalid object reference");
LuaLib.LuaPushNil (luaState); LuaLib.LuaPushNil (luaState);
return 1; return 1;
...@@ -227,7 +232,7 @@ namespace NLua ...@@ -227,7 +232,7 @@ namespace NLua
// CP: This will fail when using indexers and attempting to get a value with the same name as a property of the object, // CP: This will fail when using indexers and attempting to get a value with the same name as a property of the object,
// ie: xmlelement['item'] <- item is a property of xmlelement // ie: xmlelement['item'] <- item is a property of xmlelement
try { try {
if (!methodName.IsNull () && IsMemberPresent (objType, methodName)) if (!string.IsNullOrEmpty(methodName) && IsMemberPresent (objType, methodName))
return GetMember (luaState, objType, obj, methodName, BindingFlags.Instance | BindingFlags.IgnoreCase); return GetMember (luaState, objType, obj, methodName, BindingFlags.Instance | BindingFlags.IgnoreCase);
} catch { } catch {
} }
...@@ -258,9 +263,9 @@ namespace NLua ...@@ -258,9 +263,9 @@ namespace NLua
//check if the signature matches the input //check if the signature matches the input
if (mInfo.GetParameters ().Length == 1) { if (mInfo.GetParameters ().Length == 1) {
var getter = mInfo; var getter = mInfo;
var actualParms = (!getter.IsNull ()) ? getter.GetParameters () : null; var actualParms = (getter != null) ? getter.GetParameters () : null;
if (actualParms.IsNull () || actualParms.Length != 1) { if (actualParms == null || actualParms.Length != 1) {
translator.ThrowError (luaState, "method not found (or no indexer): " + index); translator.ThrowError (luaState, "method not found (or no indexer): " + index);
LuaLib.LuaPushNil (luaState); LuaLib.LuaPushNil (luaState);
} else { } else {
...@@ -312,7 +317,7 @@ namespace NLua ...@@ -312,7 +317,7 @@ namespace NLua
{ {
object obj = translator.GetRawNetObject (luaState, 1); object obj = translator.GetRawNetObject (luaState, 1);
if (obj.IsNull ()) { if (obj == null) {
translator.ThrowError (luaState, "trying to index an invalid object reference"); translator.ThrowError (luaState, "trying to index an invalid object reference");
LuaLib.LuaPushNil (luaState); LuaLib.LuaPushNil (luaState);
LuaLib.LuaPushBoolean (luaState, false); LuaLib.LuaPushBoolean (luaState, false);
...@@ -321,7 +326,7 @@ namespace NLua ...@@ -321,7 +326,7 @@ namespace NLua
string methodName = LuaLib.LuaToString (luaState, 2).ToString (); string methodName = LuaLib.LuaToString (luaState, 2).ToString ();
if (methodName.IsNull ()) { if (string.IsNullOrEmpty(methodName)) {
LuaLib.LuaPushNil (luaState); LuaLib.LuaPushNil (luaState);
LuaLib.LuaPushBoolean (luaState, false); LuaLib.LuaPushBoolean (luaState, false);
return 2; return 2;
...@@ -349,7 +354,7 @@ namespace NLua ...@@ -349,7 +354,7 @@ namespace NLua
{ {
object cachedMember = CheckMemberCache (memberCache, objType, methodName); object cachedMember = CheckMemberCache (memberCache, objType, methodName);
if (!cachedMember.IsNull ()) if (cachedMember != null)
return true; return true;
//CP: Removed NonPublic binding search //CP: Removed NonPublic binding search
...@@ -374,7 +379,7 @@ namespace NLua ...@@ -374,7 +379,7 @@ namespace NLua
translator.PushFunction (luaState, (LuaNativeFunction)cachedMember); translator.PushFunction (luaState, (LuaNativeFunction)cachedMember);
translator.Push (luaState, true); translator.Push (luaState, true);
return 2; return 2;
} else if (!cachedMember.IsNull ()) } else if (cachedMember != null)
member = (MemberInfo)cachedMember; member = (MemberInfo)cachedMember;
else { else {
//CP: Removed NonPublic binding search //CP: Removed NonPublic binding search
...@@ -395,11 +400,11 @@ namespace NLua ...@@ -395,11 +400,11 @@ namespace NLua
} }
} }
if (!member.IsNull ()) { if (member != null) {
if (member.MemberType == MemberTypes.Field) { if (member.MemberType == MemberTypes.Field) {
var field = (FieldInfo)member; var field = (FieldInfo)member;
if (cachedMember.IsNull ()) if (cachedMember == null)
SetMemberCache (memberCache, objType, methodName, member); SetMemberCache (memberCache, objType, methodName, member);
try { try {
...@@ -409,7 +414,7 @@ namespace NLua ...@@ -409,7 +414,7 @@ namespace NLua
} }
} else if (member.MemberType == MemberTypes.Property) { } else if (member.MemberType == MemberTypes.Property) {
var property = (PropertyInfo)member; var property = (PropertyInfo)member;
if (cachedMember.IsNull ()) if (cachedMember == null)
SetMemberCache (memberCache, objType, methodName, member); SetMemberCache (memberCache, objType, methodName, member);
try { try {
...@@ -428,7 +433,7 @@ namespace NLua ...@@ -428,7 +433,7 @@ namespace NLua
} }
} else if (member.MemberType == MemberTypes.Event) { } else if (member.MemberType == MemberTypes.Event) {
var eventInfo = (EventInfo)member; var eventInfo = (EventInfo)member;
if (cachedMember.IsNull ()) if (cachedMember == null)
SetMemberCache (memberCache, objType, methodName, member); SetMemberCache (memberCache, objType, methodName, member);
translator.Push (luaState, new RegisterEventHandler (translator.pendingEvents, obj, eventInfo)); translator.Push (luaState, new RegisterEventHandler (translator.pendingEvents, obj, eventInfo));
...@@ -436,7 +441,7 @@ namespace NLua ...@@ -436,7 +441,7 @@ namespace NLua
if (member.MemberType == MemberTypes.NestedType) { if (member.MemberType == MemberTypes.NestedType) {
// kevinh - added support for finding nested types // kevinh - added support for finding nested types
// cache us // cache us
if (cachedMember.IsNull ()) if (cachedMember == null)
SetMemberCache (memberCache, objType, methodName, member); SetMemberCache (memberCache, objType, methodName, member);
// Find the name of our class // Find the name of our class
...@@ -451,7 +456,7 @@ namespace NLua ...@@ -451,7 +456,7 @@ namespace NLua
// Member type must be 'method' // Member type must be 'method'
var wrapper = new LuaNativeFunction ((new LuaMethodWrapper (translator, objType, methodName, bindingType)).invokeFunction); var wrapper = new LuaNativeFunction ((new LuaMethodWrapper (translator, objType, methodName, bindingType)).invokeFunction);
if (cachedMember.IsNull ()) if (cachedMember == null)
SetMemberCache (memberCache, objType, methodName, wrapper); SetMemberCache (memberCache, objType, methodName, wrapper);
translator.PushFunction (luaState, wrapper); translator.PushFunction (luaState, wrapper);
...@@ -489,7 +494,7 @@ namespace NLua ...@@ -489,7 +494,7 @@ namespace NLua
object memberValue = null; object memberValue = null;
if (!members.IsNull() && membersDict.TryGetValue(memberName, out memberValue)) if (members != null && membersDict.TryGetValue(memberName, out memberValue))
{ {
return memberValue; return memberValue;
} }
...@@ -534,7 +539,7 @@ namespace NLua ...@@ -534,7 +539,7 @@ namespace NLua
{ {
object target = translator.GetRawNetObject (luaState, 1); object target = translator.GetRawNetObject (luaState, 1);
if (target.IsNull ()) { if (target == null) {
translator.ThrowError (luaState, "trying to index and invalid object reference"); translator.ThrowError (luaState, "trying to index and invalid object reference");
return 0; return 0;
} }
...@@ -558,7 +563,7 @@ namespace NLua ...@@ -558,7 +563,7 @@ namespace NLua
} else { } else {
// Try to see if we have a this[] accessor // Try to see if we have a this[] accessor
var setter = type.GetMethod ("set_Item"); var setter = type.GetMethod ("set_Item");
if (!setter.IsNull ()) { if (setter != null) {
var args = setter.GetParameters (); var args = setter.GetParameters ();
var valueType = args [1].ParameterType; var valueType = args [1].ParameterType;
...@@ -611,14 +616,14 @@ namespace NLua ...@@ -611,14 +616,14 @@ namespace NLua
// We only look up property names by string // We only look up property names by string
string fieldName = LuaLib.LuaToString (luaState, 2).ToString (); string fieldName = LuaLib.LuaToString (luaState, 2).ToString ();
if (fieldName.IsNull () || fieldName.Length < 1 || !(char.IsLetter (fieldName [0]) || fieldName [0] == '_')) { if (fieldName == null || fieldName.Length < 1 || !(char.IsLetter (fieldName [0]) || fieldName [0] == '_')) {
detailMessage = "invalid property name"; detailMessage = "invalid property name";
return false; return false;
} }
// Find our member via reflection or the cache // Find our member via reflection or the cache
var member = (MemberInfo)CheckMemberCache (memberCache, targetType, fieldName); var member = (MemberInfo)CheckMemberCache (memberCache, targetType, fieldName);
if (member.IsNull ()) { if (member == null) {
//CP: Removed NonPublic binding search and made case insensitive //CP: Removed NonPublic binding search and made case insensitive
var members = targetType.GetMember (fieldName, bindingType | BindingFlags.Public | BindingFlags.IgnoreCase/*| BindingFlags.NonPublic*/); var members = targetType.GetMember (fieldName, bindingType | BindingFlags.Public | BindingFlags.IgnoreCase/*| BindingFlags.NonPublic*/);
...@@ -686,7 +691,7 @@ namespace NLua ...@@ -686,7 +691,7 @@ namespace NLua
// If we got inside a reflection show what really happened // If we got inside a reflection show what really happened
var te = e as TargetInvocationException; var te = e as TargetInvocationException;
if (!te.IsNull ()) if (te != null)
e = te.InnerException; e = te.InnerException;
translator.ThrowError (luaState, e); translator.ThrowError (luaState, e);
...@@ -711,7 +716,7 @@ namespace NLua ...@@ -711,7 +716,7 @@ namespace NLua
IReflect klass; IReflect klass;
object obj = translator.GetRawNetObject (luaState, 1); object obj = translator.GetRawNetObject (luaState, 1);
if (obj.IsNull () || !(obj is IReflect)) { if (obj == null || !(obj is IReflect)) {
translator.ThrowError (luaState, "trying to index an invalid type reference"); translator.ThrowError (luaState, "trying to index an invalid type reference");
LuaLib.LuaPushNil (luaState); LuaLib.LuaPushNil (luaState);
return 1; return 1;
...@@ -725,7 +730,7 @@ namespace NLua ...@@ -725,7 +730,7 @@ namespace NLua
} else { } else {
string methodName = LuaLib.LuaToString (luaState, 2).ToString (); string methodName = LuaLib.LuaToString (luaState, 2).ToString ();
if (methodName.IsNull ()) { if (string.IsNullOrEmpty(methodName)) {
LuaLib.LuaPushNil (luaState); LuaLib.LuaPushNil (luaState);
return 1; return 1;
} //CP: Ignore case } //CP: Ignore case
...@@ -753,7 +758,7 @@ namespace NLua ...@@ -753,7 +758,7 @@ namespace NLua
IReflect target; IReflect target;
object obj = translator.GetRawNetObject (luaState, 1); object obj = translator.GetRawNetObject (luaState, 1);
if (obj.IsNull () || !(obj is IReflect)) { if (obj == null || !(obj is IReflect)) {
translator.ThrowError (luaState, "trying to index an invalid type reference"); translator.ThrowError (luaState, "trying to index an invalid type reference");
return 0; return 0;
} else } else
...@@ -785,7 +790,7 @@ namespace NLua ...@@ -785,7 +790,7 @@ namespace NLua
IReflect klass; IReflect klass;
object obj = translator.GetRawNetObject (luaState, 1); object obj = translator.GetRawNetObject (luaState, 1);
if (obj.IsNull () || !(obj is IReflect)) { if (obj == null || !(obj is IReflect)) {
translator.ThrowError (luaState, "trying to call constructor on an invalid type reference"); translator.ThrowError (luaState, "trying to call constructor on an invalid type reference");
LuaLib.LuaPushNil (luaState); LuaLib.LuaPushNil (luaState);
return 1; return 1;
...@@ -983,7 +988,7 @@ namespace NLua ...@@ -983,7 +988,7 @@ namespace NLua
Debug.WriteLine ("An error occurred during an attempt to retrieve a LuaTable extractor while checking for params array status."); Debug.WriteLine ("An error occurred during an attempt to retrieve a LuaTable extractor while checking for params array status.");
} }
if (!extractValue.IsNull ()) { if (extractValue != null) {
return true; return true;
} }
} else { } else {
...@@ -995,7 +1000,7 @@ namespace NLua ...@@ -995,7 +1000,7 @@ namespace NLua
Debug.WriteLine (string.Format ("An error occurred during an attempt to retrieve an extractor ({0}) while checking for params array status.", paramElementType.FullName)); Debug.WriteLine (string.Format ("An error occurred during an attempt to retrieve an extractor ({0}) while checking for params array status.", paramElementType.FullName));
} }
if (!extractValue.IsNull ()) { if (extractValue != null) {
return true; return true;
} }
} }
......
...@@ -72,7 +72,7 @@ namespace NLua.Method ...@@ -72,7 +72,7 @@ namespace NLua.Method
_Translator = translator; _Translator = translator;
_Target = target; _Target = target;
if (!targetType.IsNull ()) if (targetType != null)
_ExtractTarget = translator.typeChecker.GetExtractor (targetType); _ExtractTarget = translator.typeChecker.GetExtractor (targetType);
_Method = method; _Method = method;
...@@ -94,7 +94,7 @@ namespace NLua.Method ...@@ -94,7 +94,7 @@ namespace NLua.Method
_Translator = translator; _Translator = translator;
_MethodName = methodName; _MethodName = methodName;
if (!targetType.IsNull ()) if (targetType != null)
_ExtractTarget = translator.typeChecker.GetExtractor (targetType); _ExtractTarget = translator.typeChecker.GetExtractor (targetType);
_BindingType = bindingType; _BindingType = bindingType;
...@@ -129,14 +129,13 @@ namespace NLua.Method ...@@ -129,14 +129,13 @@ namespace NLua.Method
bool isStatic = (_BindingType & BindingFlags.Static) == BindingFlags.Static; bool isStatic = (_BindingType & BindingFlags.Static) == BindingFlags.Static;
SetPendingException (null); SetPendingException (null);
if (methodToCall.IsNull ()) { // Method from name if (methodToCall == null) { // Method from name
if (isStatic) if (isStatic)
targetObject = null; targetObject = null;
else else
targetObject = _ExtractTarget (luaState, 1); targetObject = _ExtractTarget (luaState, 1);
//LuaLib.lua_remove(luaState,1); // Pops the receiver if (_LastCalledMethod.cachedMethod != null) { // Cached?
if (!_LastCalledMethod.cachedMethod.IsNull ()) { // Cached?
int numStackToSkip = isStatic ? 0 : 1; // If this is an instance invoe we will have an extra arg on the stack for the targetObject int numStackToSkip = isStatic ? 0 : 1; // If this is an instance invoe we will have an extra arg on the stack for the targetObject
int numArgsPassed = LuaLib.LuaGetTop (luaState) - numStackToSkip; int numArgsPassed = LuaLib.LuaGetTop (luaState) - numStackToSkip;
MethodBase method = _LastCalledMethod.cachedMethod; MethodBase method = _LastCalledMethod.cachedMethod;
...@@ -162,7 +161,7 @@ namespace NLua.Method ...@@ -162,7 +161,7 @@ namespace NLua.Method
if (_LastCalledMethod.args [_LastCalledMethod.argTypes [i].index] == null && if (_LastCalledMethod.args [_LastCalledMethod.argTypes [i].index] == null &&
!LuaLib.LuaIsNil (luaState, i + 1 + numStackToSkip)) !LuaLib.LuaIsNil (luaState, i + 1 + numStackToSkip))
throw new LuaException ("argument number " + (i + 1) + " is invalid"); throw new LuaException (string.Format("argument number {0} is invalid",(i + 1)));
} }
if ((_BindingType & BindingFlags.Static) == BindingFlags.Static) if ((_BindingType & BindingFlags.Static) == BindingFlags.Static)
...@@ -191,7 +190,7 @@ namespace NLua.Method ...@@ -191,7 +190,7 @@ namespace NLua.Method
// System.Diagnostics.Debug.WriteLine("cache miss on " + methodName); // System.Diagnostics.Debug.WriteLine("cache miss on " + methodName);
// If we are running an instance variable, we can now pop the targetObject from the stack // If we are running an instance variable, we can now pop the targetObject from the stack
if (!isStatic) { if (!isStatic) {
if (targetObject.IsNull ()) { if (targetObject == null) {
_Translator.ThrowError (luaState, String.Format ("instance method '{0}' requires a non null target object", _MethodName)); _Translator.ThrowError (luaState, String.Format ("instance method '{0}' requires a non null target object", _MethodName));
LuaLib.LuaPushNil (luaState); LuaLib.LuaPushNil (luaState);
return 1; return 1;
......
...@@ -43,7 +43,7 @@ namespace NLua.Method ...@@ -43,7 +43,7 @@ namespace NLua.Method
_cachedMethod = value; _cachedMethod = value;
var mi = value as MethodInfo; var mi = value as MethodInfo;
if (!mi.IsNull ()) { if (mi != null) {
IsReturnVoid = mi.ReturnType == typeof (void); IsReturnVoid = mi.ReturnType == typeof (void);
} }
} }
......
...@@ -232,13 +232,13 @@ namespace NLua ...@@ -232,13 +232,13 @@ namespace NLua
string message = e as string; string message = e as string;
if (!message.IsNull ()) { if (message != null) {
// Wrap Lua error (just a string) and store the error location // Wrap Lua error (just a string) and store the error location
e = new LuaScriptException (message, errLocation); e = new LuaScriptException (message, errLocation);
} else { } else {
var ex = e as Exception; var ex = e as Exception;
if (!ex.IsNull ()) { if (ex != null) {
// Wrap generic .NET exception as an InnerException and store the error location // Wrap generic .NET exception as an InnerException and store the error location
e = new LuaScriptException (ex, errLocation); e = new LuaScriptException (ex, errLocation);
} }
...@@ -275,11 +275,11 @@ namespace NLua ...@@ -275,11 +275,11 @@ namespace NLua
} }
#if !SILVERLIGHT #if !SILVERLIGHT
if (assembly.IsNull ()) if (assembly == null)
assembly = Assembly.Load (AssemblyName.GetAssemblyName (assemblyName)); assembly = Assembly.Load (AssemblyName.GetAssemblyName (assemblyName));
#endif #endif
if (!assembly.IsNull () && !assemblies.Contains (assembly)) if (assembly != null && !assemblies.Contains (assembly))
assemblies.Add (assembly); assemblies.Add (assembly);
} catch (Exception e) { } catch (Exception e) {
ThrowError (luaState, e); ThrowError (luaState, e);
...@@ -293,7 +293,7 @@ namespace NLua ...@@ -293,7 +293,7 @@ namespace NLua
foreach (var assembly in assemblies) { foreach (var assembly in assemblies) {
var klass = assembly.GetType (className); var klass = assembly.GetType (className);
if (!klass.IsNull ()) if (klass != null)
return klass; return klass;
} }
return null; return null;
...@@ -318,7 +318,7 @@ namespace NLua ...@@ -318,7 +318,7 @@ namespace NLua
string className = LuaLib.LuaToString (luaState, 1).ToString (); string className = LuaLib.LuaToString (luaState, 1).ToString ();
var klass = FindType (className); var klass = FindType (className);
if (!klass.IsNull ()) if (klass != null)
PushType (luaState, klass); PushType (luaState, klass);
else else
LuaLib.LuaPushNil (luaState); LuaLib.LuaPushNil (luaState);
...@@ -347,10 +347,10 @@ namespace NLua ...@@ -347,10 +347,10 @@ namespace NLua
var luaTable = GetTable (luaState, 1); var luaTable = GetTable (luaState, 1);
string superclassName = LuaLib.LuaToString (luaState, 2).ToString (); string superclassName = LuaLib.LuaToString (luaState, 2).ToString ();
if (!superclassName.IsNull ()) { if (superclassName != null) {
var klass = FindType (superclassName); var klass = FindType (superclassName);
if (!klass.IsNull ()) { if (klass != null) {
// Creates and pushes the object in the stack, setting // Creates and pushes the object in the stack, setting
// it as the metatable of the first argument // it as the metatable of the first argument
object obj = CodeGeneration.Instance.GetClassInstance (klass, luaTable); object obj = CodeGeneration.Instance.GetClassInstance (klass, luaTable);
...@@ -401,12 +401,12 @@ namespace NLua ...@@ -401,12 +401,12 @@ namespace NLua
LuaLib.LuaGetTable (luaState, -2); LuaLib.LuaGetTable (luaState, -2);
object obj = GetRawNetObject (luaState, -1); object obj = GetRawNetObject (luaState, -1);
if (obj.IsNull ()) if (obj == null)
ThrowError (luaState, "unregister_table: arg is not valid table"); ThrowError (luaState, "unregister_table: arg is not valid table");
var luaTableField = obj.GetType ().GetField ("__luaInterface_luaTable"); var luaTableField = obj.GetType ().GetField ("__luaInterface_luaTable");
if (luaTableField.IsNull ()) if (luaTableField == null)
ThrowError (luaState, "unregister_table: arg is not valid table"); ThrowError (luaState, "unregister_table: arg is not valid table");
luaTableField.SetValue (obj, null); luaTableField.SetValue (obj, null);
...@@ -450,7 +450,7 @@ namespace NLua ...@@ -450,7 +450,7 @@ namespace NLua
} else { } else {
target = GetRawNetObject (luaState, 1); target = GetRawNetObject (luaState, 1);
if (target.IsNull ()) { if (target == null) {
ThrowError (luaState, "get_method_bysig: first arg is not type or object reference"); ThrowError (luaState, "get_method_bysig: first arg is not type or object reference");
LuaLib.LuaPushNil (luaState); LuaLib.LuaPushNil (luaState);
return 1; return 1;
...@@ -500,7 +500,7 @@ namespace NLua ...@@ -500,7 +500,7 @@ namespace NLua
if (udata != -1) if (udata != -1)
klass = (IReflect)objects [udata]; klass = (IReflect)objects [udata];
if (klass.IsNull ()) if (klass == null)
ThrowError (luaState, "get_constructor_bysig: first arg is invalid type reference"); ThrowError (luaState, "get_constructor_bysig: first arg is invalid type reference");
var signature = new Type[LuaLib.LuaGetTop (luaState) - 1]; var signature = new Type[LuaLib.LuaGetTop (luaState) - 1];
...@@ -544,7 +544,7 @@ namespace NLua ...@@ -544,7 +544,7 @@ namespace NLua
int index = -1; int index = -1;
// Pushes nil // Pushes nil
if (o.IsNull ()) { if (o == null) {
LuaLib.LuaPushNil (luaState); LuaLib.LuaPushNil (luaState);
return; return;
} }
...@@ -632,7 +632,7 @@ namespace NLua ...@@ -632,7 +632,7 @@ namespace NLua
internal object GetAsType (LuaState luaState, int stackPos, Type paramType) internal object GetAsType (LuaState luaState, int stackPos, Type paramType)
{ {
var extractor = typeChecker.CheckLuaType (luaState, stackPos, paramType); var extractor = typeChecker.CheckLuaType (luaState, stackPos, paramType);
return !extractor.IsNull () ? extractor (luaState, stackPos) : null; return extractor != null ? extractor (luaState, stackPos) : null;
} }
/// <summary> /// <summary>
...@@ -757,20 +757,6 @@ namespace NLua ...@@ -757,20 +757,6 @@ namespace NLua
return udata != -1 ? objects [udata] : null; return udata != -1 ? objects [udata] : null;
} }
/*
* Pushes the entire array into the Lua stack and returns the number
* of elements pushed.
*/
internal int ReturnValues (LuaState luaState, object[] returnValues)
{
if (LuaLib.LuaCheckStack (luaState, returnValues.Length + 5)) {
for (int i = 0; i < returnValues.Length; i++)
Push (luaState, returnValues [i]);
return returnValues.Length;
} else
return 0;
}
/* /*
* Gets the values from the provided index to * Gets the values from the provided index to
...@@ -829,13 +815,9 @@ namespace NLua ...@@ -829,13 +815,9 @@ namespace NLua
if (o is ILuaGeneratedType) { if (o is ILuaGeneratedType) {
// Make sure we are _really_ ILuaGenerated // Make sure we are _really_ ILuaGenerated
var typ = o.GetType (); var typ = o.GetType ();
#if SILVERLIGHT return typ.GetInterface ("ILuaGeneratedType", true) != null;
return (!typ.GetInterface ("ILuaGeneratedType", true).IsNull ()); }
#else return false;
return (!typ.GetInterface ("ILuaGeneratedType").IsNull ());
#endif
} else
return false;
} }
/* /*
...@@ -843,7 +825,7 @@ namespace NLua ...@@ -843,7 +825,7 @@ namespace NLua
*/ */
internal void Push (LuaState luaState, object o) internal void Push (LuaState luaState, object o)
{ {
if (o.IsNull ()) if (o == null)
LuaLib.LuaPushNil (luaState); LuaLib.LuaPushNil (luaState);
else if (o is sbyte || o is byte || o is short || o is ushort || else if (o is sbyte || o is byte || o is short || o is ushort ||
o is int || o is uint || o is long || o is float || o is int || o is uint || o is long || o is float ||
......
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