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

Removed IReflect dependency. (Windows Store doesn't support IReflect) :)

parent 2bcd5944
...@@ -60,9 +60,6 @@ ...@@ -60,9 +60,6 @@
<Compile Include="..\tests\Entity.cs"> <Compile Include="..\tests\Entity.cs">
<Link>Entity.cs</Link> <Link>Entity.cs</Link>
</Compile> </Compile>
<Compile Include="..\tests\TestLua.cs">
<Link>TestLua.cs</Link>
</Compile>
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
...@@ -79,7 +76,7 @@ ...@@ -79,7 +76,7 @@
--> -->
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Core\KopiLua\KopiLua\KopiLua.Net45.csproj"> <ProjectReference Include="..\Core\KopiLua\KopiLua\KopiLua.Net45.csproj">
<Project>{e8ddbc21-ef74-4aba-9c49-bfc702be25d8}</Project> <Project>{E8DDBC21-EF74-4ABA-9C49-BFC702BE25D8}</Project>
<Name>KopiLua.Net45</Name> <Name>KopiLua.Net45</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\Core\NLua\NLua.Net45.csproj"> <ProjectReference Include="..\Core\NLua\NLua.Net45.csproj">
......
...@@ -84,7 +84,7 @@ namespace NLua ...@@ -84,7 +84,7 @@ namespace NLua
* Checks if the value at Lua stack index stackPos matches paramType, * Checks if the value at Lua stack index stackPos matches paramType,
* returning a conversion function if it does and null otherwise. * returning a conversion function if it does and null otherwise.
*/ */
internal ExtractValue GetExtractor (IReflect paramType) internal ExtractValue GetExtractor (ProxyType paramType)
{ {
return GetExtractor (paramType.UnderlyingSystemType); return GetExtractor (paramType.UnderlyingSystemType);
} }
......
...@@ -1103,7 +1103,7 @@ end ...@@ -1103,7 +1103,7 @@ end
{ {
// We leave nothing on the stack when we are done // We leave nothing on the stack when we are done
int oldTop = LuaLib.LuaGetTop (luaState); int oldTop = LuaLib.LuaGetTop (luaState);
var wrapper = new LuaMethodWrapper (translator, target, function.DeclaringType, function); var wrapper = new LuaMethodWrapper (translator, target, new ProxyType(function.DeclaringType), function);
translator.Push (luaState, new LuaNativeFunction (wrapper.invokeFunction)); translator.Push (luaState, new LuaNativeFunction (wrapper.invokeFunction));
this [path] = translator.GetObject (luaState, -1); this [path] = translator.GetObject (luaState, -1);
var f = GetFunction (path); var f = GetFunction (path);
......
...@@ -398,14 +398,14 @@ namespace NLua ...@@ -398,14 +398,14 @@ namespace NLua
//var indexType = index.GetType(); //var indexType = index.GetType();
string methodName = index as string; // will be null if not a string arg string methodName = index as string; // will be null if not a string arg
var objType = obj.GetType (); var objType = obj.GetType ();
var proxyType = new ProxyType (objType);
// Handle the most common case, looking up the method by name. // Handle the most common case, looking up the method by name.
// 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 (!string.IsNullOrEmpty(methodName) && IsMemberPresent (objType, methodName)) if (!string.IsNullOrEmpty(methodName) && IsMemberPresent (proxyType, methodName))
return GetMember (luaState, objType, obj, methodName, BindingFlags.Instance); return GetMember (luaState, proxyType, obj, methodName, BindingFlags.Instance);
} catch { } catch {
} }
...@@ -508,12 +508,12 @@ namespace NLua ...@@ -508,12 +508,12 @@ namespace NLua
return 2; return 2;
} }
GetMember (luaState, obj.GetType (), obj, "__luaInterface_base_" + methodName, BindingFlags.Instance); GetMember (luaState, new ProxyType(obj.GetType ()), obj, "__luaInterface_base_" + methodName, BindingFlags.Instance);
LuaLib.LuaSetTop (luaState, -2); LuaLib.LuaSetTop (luaState, -2);
if (LuaLib.LuaType (luaState, -1) == LuaTypes.Nil) { if (LuaLib.LuaType (luaState, -1) == LuaTypes.Nil) {
LuaLib.LuaSetTop (luaState, -2); LuaLib.LuaSetTop (luaState, -2);
return GetMember (luaState, obj.GetType (), obj, methodName, BindingFlags.Instance); return GetMember (luaState, new ProxyType(obj.GetType ()), obj, methodName, BindingFlags.Instance);
} }
LuaLib.LuaPushBoolean (luaState, false); LuaLib.LuaPushBoolean (luaState, false);
...@@ -526,7 +526,7 @@ namespace NLua ...@@ -526,7 +526,7 @@ namespace NLua
/// <param name="objType"></param> /// <param name="objType"></param>
/// <param name="methodName"></param> /// <param name="methodName"></param>
/// <returns></returns> /// <returns></returns>
bool IsMemberPresent (IReflect objType, string methodName) bool IsMemberPresent (ProxyType objType, string methodName)
{ {
object cachedMember = CheckMemberCache (memberCache, objType, methodName); object cachedMember = CheckMemberCache (memberCache, objType, methodName);
...@@ -558,7 +558,7 @@ namespace NLua ...@@ -558,7 +558,7 @@ namespace NLua
} }
MethodInfo methodInfo = translator.GetExtensionMethod (type, name); MethodInfo methodInfo = translator.GetExtensionMethod (type, name);
var wrapper = new LuaNativeFunction ((new LuaMethodWrapper (translator, obj, type, methodInfo)).invokeFunction); var wrapper = new LuaNativeFunction ((new LuaMethodWrapper (translator, obj,new ProxyType(type), methodInfo)).invokeFunction);
SetMemberCache (memberCache, type, name, wrapper); SetMemberCache (memberCache, type, name, wrapper);
...@@ -573,7 +573,7 @@ namespace NLua ...@@ -573,7 +573,7 @@ namespace NLua
* Uses reflection to find members, and stores the reflected MemberInfo object in * Uses reflection to find members, and stores the reflected MemberInfo object in
* a cache (indexed by the type of the object and the name of the member). * a cache (indexed by the type of the object and the name of the member).
*/ */
int GetMember (LuaState luaState, IReflect objType, object obj, string methodName, BindingFlags bindingType) int GetMember (LuaState luaState, ProxyType objType, object obj, string methodName, BindingFlags bindingType)
{ {
bool implicitStatic = false; bool implicitStatic = false;
MemberInfo member = null; MemberInfo member = null;
...@@ -624,8 +624,8 @@ namespace NLua ...@@ -624,8 +624,8 @@ namespace NLua
} catch (ArgumentException) { } catch (ArgumentException) {
// If we can't find the getter in our class, recurse up to the base class and see // If we can't find the getter in our class, recurse up to the base class and see
// if they can help. // if they can help.
if (objType is Type && !(((Type)objType) == typeof(object))) if (objType.UnderlyingSystemType != typeof(object))
return GetMember (luaState, ((Type)objType).BaseType, obj, methodName, bindingType); return GetMember (luaState, new ProxyType(objType.UnderlyingSystemType.BaseType), obj, methodName, bindingType);
else else
LuaLib.LuaPushNil (luaState); LuaLib.LuaPushNil (luaState);
} catch (TargetInvocationException e) { // Convert this exception into a Lua error } catch (TargetInvocationException e) { // Convert this exception into a Lua error
...@@ -685,7 +685,12 @@ namespace NLua ...@@ -685,7 +685,12 @@ namespace NLua
/* /*
* Checks if a MemberInfo object is cached, returning it or null. * Checks if a MemberInfo object is cached, returning it or null.
*/ */
private object CheckMemberCache (Dictionary<object, object> memberCache, IReflect objType, string memberName) object CheckMemberCache (Dictionary<object, object> memberCache, Type objType, string memberName)
{
return CheckMemberCache (memberCache, new ProxyType (objType), memberName);
}
object CheckMemberCache (Dictionary<object, object> memberCache, ProxyType objType, string memberName)
{ {
object members = null; object members = null;
...@@ -707,7 +712,12 @@ namespace NLua ...@@ -707,7 +712,12 @@ namespace NLua
/* /*
* Stores a MemberInfo object in the member cache. * Stores a MemberInfo object in the member cache.
*/ */
private void SetMemberCache (Dictionary<object, object> memberCache, IReflect objType, string memberName, object member) void SetMemberCache (Dictionary<object, object> memberCache, Type objType, string memberName, object member)
{
SetMemberCache (memberCache, new ProxyType (objType), memberName, member);
}
void SetMemberCache (Dictionary<object, object> memberCache, ProxyType objType, string memberName, object member)
{ {
Dictionary<object, object> members = null; Dictionary<object, object> members = null;
object memberCacheValue = null; object memberCacheValue = null;
...@@ -751,7 +761,7 @@ namespace NLua ...@@ -751,7 +761,7 @@ namespace NLua
// First try to look up the parameter as a property name // First try to look up the parameter as a property name
string detailMessage; string detailMessage;
bool didMember = TrySetMember (luaState, type, target, BindingFlags.Instance, out detailMessage); bool didMember = TrySetMember (luaState, new ProxyType(type), target, BindingFlags.Instance, out detailMessage);
if (didMember) if (didMember)
return 0; // Must have found the property name return 0; // Must have found the property name
...@@ -804,7 +814,7 @@ namespace NLua ...@@ -804,7 +814,7 @@ namespace NLua
/// <param name="target"></param> /// <param name="target"></param>
/// <param name="bindingType"></param> /// <param name="bindingType"></param>
/// <returns>false if unable to find the named member, true for success</returns> /// <returns>false if unable to find the named member, true for success</returns>
private bool TrySetMember (LuaState luaState, IReflect targetType, object target, BindingFlags bindingType, out string detailMessage) bool TrySetMember (LuaState luaState, ProxyType targetType, object target, BindingFlags bindingType, out string detailMessage)
{ {
detailMessage = null; // No error yet detailMessage = null; // No error yet
...@@ -872,7 +882,7 @@ namespace NLua ...@@ -872,7 +882,7 @@ namespace NLua
* Writes to fields or properties, either static or instance. Throws an error * Writes to fields or properties, either static or instance. Throws an error
* if the operation is invalid. * if the operation is invalid.
*/ */
private int SetMember (LuaState luaState, IReflect targetType, object target, BindingFlags bindingType) private int SetMember (LuaState luaState, ProxyType targetType, object target, BindingFlags bindingType)
{ {
string detail; string detail;
bool success = TrySetMember (luaState, targetType, target, bindingType, out detail); bool success = TrySetMember (luaState, targetType, target, bindingType, out detail);
...@@ -915,15 +925,15 @@ namespace NLua ...@@ -915,15 +925,15 @@ namespace NLua
private int GetClassMethodInternal (LuaState luaState) private int GetClassMethodInternal (LuaState luaState)
{ {
IReflect klass; ProxyType klass;
object obj = translator.GetRawNetObject (luaState, 1); object obj = translator.GetRawNetObject (luaState, 1);
if (obj == null || !(obj is IReflect)) { if (obj == null || !(obj is ProxyType)) {
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;
} else } else
klass = (IReflect)obj; klass = (ProxyType)obj;
if (LuaLib.LuaIsNumber (luaState, 2)) { if (LuaLib.LuaIsNumber (luaState, 2)) {
int size = (int)LuaLib.LuaToNumber (luaState, 2); int size = (int)LuaLib.LuaToNumber (luaState, 2);
...@@ -957,14 +967,14 @@ namespace NLua ...@@ -957,14 +967,14 @@ namespace NLua
private int SetClassFieldOrPropertyInternal (LuaState luaState) private int SetClassFieldOrPropertyInternal (LuaState luaState)
{ {
IReflect target; ProxyType target;
object obj = translator.GetRawNetObject (luaState, 1); object obj = translator.GetRawNetObject (luaState, 1);
if (obj == null || !(obj is IReflect)) { if (obj == null || !(obj is ProxyType)) {
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
target = (IReflect)obj; target = (ProxyType)obj;
return SetMember (luaState, target, null, BindingFlags.FlattenHierarchy | BindingFlags.Static); return SetMember (luaState, target, null, BindingFlags.FlattenHierarchy | BindingFlags.Static);
} }
...@@ -989,15 +999,15 @@ namespace NLua ...@@ -989,15 +999,15 @@ namespace NLua
private int CallConstructorInternal (LuaState luaState) private int CallConstructorInternal (LuaState luaState)
{ {
var validConstructor = new MethodCache (); var validConstructor = new MethodCache ();
IReflect klass; ProxyType klass;
object obj = translator.GetRawNetObject (luaState, 1); object obj = translator.GetRawNetObject (luaState, 1);
if (obj == null || !(obj is IReflect)) { if (obj == null || !(obj is ProxyType)) {
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;
} else } else
klass = (IReflect)obj; klass = (ProxyType)obj;
LuaLib.LuaRemove (luaState, 1); LuaLib.LuaRemove (luaState, 1);
var constructors = klass.UnderlyingSystemType.GetConstructors (); var constructors = klass.UnderlyingSystemType.GetConstructors ();
......
...@@ -66,7 +66,7 @@ namespace NLua.Method ...@@ -66,7 +66,7 @@ namespace NLua.Method
/* /*
* Constructs the wrapper for a known MethodBase instance * Constructs the wrapper for a known MethodBase instance
*/ */
public LuaMethodWrapper (ObjectTranslator translator, object target, IReflect targetType, MethodBase method) public LuaMethodWrapper (ObjectTranslator translator, object target, ProxyType targetType, MethodBase method)
{ {
invokeFunction = new LuaNativeFunction (this.Call); invokeFunction = new LuaNativeFunction (this.Call);
_Translator = translator; _Translator = translator;
...@@ -87,7 +87,7 @@ namespace NLua.Method ...@@ -87,7 +87,7 @@ namespace NLua.Method
/* /*
* Constructs the wrapper for a known method name * Constructs the wrapper for a known method name
*/ */
public LuaMethodWrapper (ObjectTranslator translator, IReflect targetType, string methodName, BindingFlags bindingType) public LuaMethodWrapper (ObjectTranslator translator, ProxyType targetType, string methodName, BindingFlags bindingType)
{ {
invokeFunction = new LuaNativeFunction (this.Call); invokeFunction = new LuaNativeFunction (this.Call);
......
...@@ -480,12 +480,12 @@ namespace NLua ...@@ -480,12 +480,12 @@ namespace NLua
private int GetMethodSignatureInternal (LuaState luaState) private int GetMethodSignatureInternal (LuaState luaState)
{ {
IReflect klass; ProxyType klass;
object target; object target;
int udata = LuaLib.LuaNetCheckUData (luaState, 1, "luaNet_class"); int udata = LuaLib.LuaNetCheckUData (luaState, 1, "luaNet_class");
if (udata != -1) { if (udata != -1) {
klass = (IReflect)objects [udata]; klass = (ProxyType)objects [udata];
target = null; target = null;
} else { } else {
target = GetRawNetObject (luaState, 1); target = GetRawNetObject (luaState, 1);
...@@ -496,7 +496,7 @@ namespace NLua ...@@ -496,7 +496,7 @@ namespace NLua
return 1; return 1;
} }
klass = target.GetType (); klass = new ProxyType(target.GetType ());
} }
string methodName = LuaLib.LuaToString (luaState, 2).ToString (); string methodName = LuaLib.LuaToString (luaState, 2).ToString ();
...@@ -533,11 +533,11 @@ namespace NLua ...@@ -533,11 +533,11 @@ namespace NLua
private int GetConstructorSignatureInternal (LuaState luaState) private int GetConstructorSignatureInternal (LuaState luaState)
{ {
IReflect klass = null; ProxyType klass = null;
int udata = LuaLib.LuaNetCheckUData (luaState, 1, "luaNet_class"); int udata = LuaLib.LuaNetCheckUData (luaState, 1, "luaNet_class");
if (udata != -1) if (udata != -1)
klass = (IReflect)objects [udata]; klass = (ProxyType)objects [udata];
if (klass == null) 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");
......
...@@ -32,7 +32,7 @@ namespace NLua ...@@ -32,7 +32,7 @@ namespace NLua
/// <summary> /// <summary>
/// Summary description for ProxyType. /// Summary description for ProxyType.
/// </summary> /// </summary>
public class ProxyType : IReflect public class ProxyType
{ {
private Type proxy; private Type proxy;
...@@ -54,14 +54,18 @@ namespace NLua ...@@ -54,14 +54,18 @@ namespace NLua
get { return proxy; } get { return proxy; }
} }
public FieldInfo GetField (string name, BindingFlags bindingAttr) public override bool Equals (object obj)
{ {
return proxy.GetField (name, bindingAttr); if (obj is Type)
return proxy.Equals ((Type)obj);
if (obj is ProxyType)
return proxy.Equals (((ProxyType)obj).UnderlyingSystemType);
return proxy.Equals (obj);
} }
public FieldInfo[] GetFields (BindingFlags bindingAttr) public override int GetHashCode ()
{ {
return proxy.GetFields (bindingAttr); return proxy.GetHashCode ();
} }
public MemberInfo[] GetMember (string name, BindingFlags bindingAttr) public MemberInfo[] GetMember (string name, BindingFlags bindingAttr)
...@@ -69,44 +73,9 @@ namespace NLua ...@@ -69,44 +73,9 @@ namespace NLua
return proxy.GetMember (name, bindingAttr); return proxy.GetMember (name, bindingAttr);
} }
public MemberInfo[] GetMembers (BindingFlags bindingAttr)
{
return proxy.GetMembers (bindingAttr);
}
public MethodInfo GetMethod (string name, BindingFlags bindingAttr)
{
return proxy.GetMethod (name, bindingAttr);
}
public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers) public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers)
{ {
return proxy.GetMethod (name, bindingAttr, binder, types, modifiers); return proxy.GetMethod (name, bindingAttr, binder, types, modifiers);
} }
public MethodInfo[] GetMethods (BindingFlags bindingAttr)
{
return proxy.GetMethods (bindingAttr);
}
public PropertyInfo GetProperty (string name, BindingFlags bindingAttr)
{
return proxy.GetProperty (name, bindingAttr);
}
public PropertyInfo GetProperty (string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
{
return proxy.GetProperty (name, bindingAttr, binder, returnType, types, modifiers);
}
public PropertyInfo[] GetProperties (BindingFlags bindingAttr)
{
return proxy.GetProperties (bindingAttr);
}
public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters)
{
return proxy.InvokeMember (name, invokeAttr, binder, target, args, modifiers, culture, namedParameters);
}
} }
} }
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment