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

Merge pull request #15 from Mangatome/wp7support

Support of Windows Phone 7 and Silverlight 4.
parents 305833b3 4cfc1f2b
...@@ -45,31 +45,35 @@ namespace NLua ...@@ -45,31 +45,35 @@ namespace NLua
*/ */
class CheckType class CheckType
{ {
#if SILVERLIGHT
private Dictionary<Type, ExtractValue> extractValues = new Dictionary<Type, ExtractValue>();
#else
private Dictionary<long, ExtractValue> extractValues = new Dictionary<long, ExtractValue> (); private Dictionary<long, ExtractValue> extractValues = new Dictionary<long, ExtractValue> ();
#endif
private ExtractValue extractNetObject; private ExtractValue extractNetObject;
private ObjectTranslator translator; private ObjectTranslator translator;
public CheckType (ObjectTranslator translator) public CheckType (ObjectTranslator translator)
{ {
this.translator = translator; this.translator = translator;
extractValues.Add (typeof(object).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsObject)); extractValues.Add(getExtractDictionaryKey(typeof(object)), new ExtractValue(getAsObject));
extractValues.Add (typeof(sbyte).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsSbyte)); extractValues.Add(getExtractDictionaryKey(typeof(sbyte)), new ExtractValue(getAsSbyte));
extractValues.Add (typeof(byte).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsByte)); extractValues.Add(getExtractDictionaryKey(typeof(byte)), new ExtractValue(getAsByte));
extractValues.Add (typeof(short).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsShort)); extractValues.Add(getExtractDictionaryKey(typeof(short)), new ExtractValue(getAsShort));
extractValues.Add (typeof(ushort).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsUshort)); extractValues.Add(getExtractDictionaryKey(typeof(ushort)), new ExtractValue(getAsUshort));
extractValues.Add (typeof(int).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsInt)); extractValues.Add(getExtractDictionaryKey(typeof(int)), new ExtractValue(getAsInt));
extractValues.Add (typeof(uint).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsUint)); extractValues.Add(getExtractDictionaryKey(typeof(uint)), new ExtractValue(getAsUint));
extractValues.Add (typeof(long).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsLong)); extractValues.Add(getExtractDictionaryKey(typeof(long)), new ExtractValue(getAsLong));
extractValues.Add (typeof(ulong).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsUlong)); extractValues.Add(getExtractDictionaryKey(typeof(ulong)), new ExtractValue(getAsUlong));
extractValues.Add (typeof(double).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsDouble)); extractValues.Add(getExtractDictionaryKey(typeof(double)), new ExtractValue(getAsDouble));
extractValues.Add (typeof(char).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsChar)); extractValues.Add(getExtractDictionaryKey(typeof(char)), new ExtractValue(getAsChar));
extractValues.Add (typeof(float).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsFloat)); extractValues.Add(getExtractDictionaryKey(typeof(float)), new ExtractValue(getAsFloat));
extractValues.Add (typeof(decimal).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsDecimal)); extractValues.Add(getExtractDictionaryKey(typeof(decimal)), new ExtractValue(getAsDecimal));
extractValues.Add (typeof(bool).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsBoolean)); extractValues.Add(getExtractDictionaryKey(typeof(bool)), new ExtractValue(getAsBoolean));
extractValues.Add (typeof(string).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsString)); extractValues.Add(getExtractDictionaryKey(typeof(string)), new ExtractValue(getAsString));
extractValues.Add (typeof(LuaFunction).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsFunction)); extractValues.Add(getExtractDictionaryKey(typeof(LuaFunction)), new ExtractValue(getAsFunction));
extractValues.Add (typeof(LuaTable).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsTable)); extractValues.Add(getExtractDictionaryKey(typeof(LuaTable)), new ExtractValue(getAsTable));
extractValues.Add (typeof(LuaUserData).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsUserdata)); extractValues.Add(getExtractDictionaryKey(typeof(LuaUserData)), new ExtractValue(getAsUserdata));
extractNetObject = new ExtractValue (getAsNetObject); extractNetObject = new ExtractValue (getAsNetObject);
} }
...@@ -86,9 +90,9 @@ namespace NLua ...@@ -86,9 +90,9 @@ namespace NLua
{ {
if (paramType.IsByRef) if (paramType.IsByRef)
paramType = paramType.GetElementType (); paramType = paramType.GetElementType ();
long runtimeHandleValue = paramType.TypeHandle.Value.ToInt64 (); var extractKey = getExtractDictionaryKey(paramType);
return extractValues.ContainsKey (runtimeHandleValue) ? extractValues [runtimeHandleValue] : extractNetObject; return extractValues.ContainsKey(extractKey) ? extractValues[extractKey] : extractNetObject;
} }
internal ExtractValue checkType (LuaCore.lua_State luaState, int stackPos, Type paramType) internal ExtractValue checkType (LuaCore.lua_State luaState, int stackPos, Type paramType)
...@@ -102,48 +106,48 @@ namespace NLua ...@@ -102,48 +106,48 @@ namespace NLua
if (!underlyingType.IsNull ()) if (!underlyingType.IsNull ())
paramType = underlyingType; // Silently convert nullable types to their non null requics paramType = underlyingType; // Silently convert nullable types to their non null requics
long runtimeHandleValue = paramType.TypeHandle.Value.ToInt64 (); var extractKey = getExtractDictionaryKey (paramType);
if (paramType.Equals (typeof(object))) if (paramType.Equals (typeof(object)))
return extractValues [runtimeHandleValue]; return extractValues [extractKey];
//CP: Added support for generic parameters //CP: Added support for generic parameters
if (paramType.IsGenericParameter) { if (paramType.IsGenericParameter) {
if (luatype == LuaTypes.Boolean) if (luatype == LuaTypes.Boolean)
return extractValues [typeof(bool).TypeHandle.Value.ToInt64 ()]; return extractValues [getExtractDictionaryKey (typeof(bool))];
else if (luatype == LuaTypes.String) else if (luatype == LuaTypes.String)
return extractValues [typeof(string).TypeHandle.Value.ToInt64 ()]; return extractValues[getExtractDictionaryKey (typeof(string))];
else if (luatype == LuaTypes.Table) else if (luatype == LuaTypes.Table)
return extractValues [typeof(LuaTable).TypeHandle.Value.ToInt64 ()]; return extractValues [getExtractDictionaryKey (typeof(LuaTable))];
else if (luatype == LuaTypes.UserData) else if (luatype == LuaTypes.UserData)
return extractValues [typeof(object).TypeHandle.Value.ToInt64 ()]; return extractValues [getExtractDictionaryKey (typeof(object))];
else if (luatype == LuaTypes.Function) else if (luatype == LuaTypes.Function)
return extractValues [typeof(LuaFunction).TypeHandle.Value.ToInt64 ()]; return extractValues [getExtractDictionaryKey (typeof(LuaFunction))];
else if (luatype == LuaTypes.Number) else if (luatype == LuaTypes.Number)
return extractValues [typeof(double).TypeHandle.Value.ToInt64 ()]; return extractValues [getExtractDictionaryKey (typeof(double))];
} }
if (LuaLib.lua_isnumber (luaState, stackPos)) if (LuaLib.lua_isnumber (luaState, stackPos))
return extractValues [runtimeHandleValue]; return extractValues [extractKey];
if (paramType == typeof(bool)) { if (paramType == typeof(bool)) {
if (LuaLib.lua_isboolean (luaState, stackPos)) if (LuaLib.lua_isboolean (luaState, stackPos))
return extractValues [runtimeHandleValue]; return extractValues [extractKey];
} else if (paramType == typeof(string)) { } else if (paramType == typeof(string)) {
if (LuaLib.lua_isstring (luaState, stackPos)) if (LuaLib.lua_isstring (luaState, stackPos))
return extractValues [runtimeHandleValue]; return extractValues [extractKey];
else if (luatype == LuaTypes.Nil) else if (luatype == LuaTypes.Nil)
return extractNetObject; // kevinh - silently convert nil to a null string pointer return extractNetObject; // kevinh - silently convert nil to a null string pointer
} else if (paramType == typeof(LuaTable)) { } else if (paramType == typeof(LuaTable)) {
if (luatype == LuaTypes.Table) if (luatype == LuaTypes.Table)
return extractValues [runtimeHandleValue]; return extractValues [extractKey];
} else if (paramType == typeof(LuaUserData)) { } else if (paramType == typeof(LuaUserData)) {
if (luatype == LuaTypes.UserData) if (luatype == LuaTypes.UserData)
return extractValues [runtimeHandleValue]; return extractValues [extractKey];
} else if (paramType == typeof(LuaFunction)) { } else if (paramType == typeof(LuaFunction)) {
if (luatype == LuaTypes.Function) if (luatype == LuaTypes.Function)
return extractValues [runtimeHandleValue]; return extractValues [extractKey];
} else if (typeof(Delegate).IsAssignableFrom (paramType) && luatype == LuaTypes.Function) } else if (typeof(Delegate).IsAssignableFrom (paramType) && luatype == LuaTypes.Function)
return new ExtractValue (new DelegateGenerator (translator, paramType).extractGenerated); return new ExtractValue (new DelegateGenerator (translator, paramType).extractGenerated);
else if (paramType.IsInterface && luatype == LuaTypes.Table) else if (paramType.IsInterface && luatype == LuaTypes.Table)
...@@ -166,7 +170,19 @@ namespace NLua ...@@ -166,7 +170,19 @@ namespace NLua
} }
return null; return null;
}
#if SILVERLIGHT
private Type getExtractDictionaryKey(Type targetType)
{
return targetType;
}
#else
private long getExtractDictionaryKey(Type targetType)
{
return targetType.TypeHandle.Value.ToInt64();
} }
#endif
/* /*
* The following functions return the value in the Lua stack * The following functions return the value in the Lua stack
......
...@@ -24,14 +24,18 @@ ...@@ -24,14 +24,18 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
using System; using System;
#if !SILVERLIGHT
using System.Runtime.Serialization; using System.Runtime.Serialization;
#endif
namespace NLua.Exceptions namespace NLua.Exceptions
{ {
/// <summary> /// <summary>
/// Exceptions thrown by the Lua runtime /// Exceptions thrown by the Lua runtime
/// </summary> /// </summary>
#if !SILVERLIGHT
[Serializable] [Serializable]
#endif
public class LuaException : Exception public class LuaException : Exception
{ {
public LuaException () public LuaException ()
...@@ -46,8 +50,10 @@ namespace NLua.Exceptions ...@@ -46,8 +50,10 @@ namespace NLua.Exceptions
{ {
} }
#if !SILVERLIGHT
protected LuaException (SerializationInfo info, StreamingContext context) : base(info, context) protected LuaException (SerializationInfo info, StreamingContext context) : base(info, context)
{ {
} }
#endif
} }
} }
\ No newline at end of file
...@@ -42,7 +42,11 @@ namespace NLua.Exceptions ...@@ -42,7 +42,11 @@ namespace NLua.Exceptions
/// <summary> /// <summary>
/// The position in the script where the exception was triggered. /// The position in the script where the exception was triggered.
/// </summary> /// </summary>
#if SILVERLIGHT
public string Source { get { return source; } }
#else
public override string Source { get { return source; } } public override string Source { get { return source; } }
#endif
/// <summary> /// <summary>
/// Creates a new Lua-only exception. /// Creates a new Lua-only exception.
......
...@@ -51,7 +51,7 @@ namespace NLua ...@@ -51,7 +51,7 @@ namespace NLua
private static readonly CodeGeneration instance = new CodeGeneration (); private static readonly CodeGeneration instance = new CodeGeneration ();
private AssemblyName assemblyName; private AssemblyName assemblyName;
#if !MONOTOUCH #if !MONOTOUCH && !SILVERLIGHT
private Dictionary<Type, Type> eventHandlerCollection = new Dictionary<Type, Type> (); private Dictionary<Type, Type> eventHandlerCollection = new Dictionary<Type, Type> ();
private Type eventHandlerParent = typeof(LuaEventHandler); private Type eventHandlerParent = typeof(LuaEventHandler);
private Type delegateParent = typeof(LuaDelegate); private Type delegateParent = typeof(LuaDelegate);
...@@ -74,7 +74,7 @@ namespace NLua ...@@ -74,7 +74,7 @@ namespace NLua
assemblyName = new AssemblyName (); assemblyName = new AssemblyName ();
assemblyName.Name = "NLua_generatedcode"; assemblyName.Name = "NLua_generatedcode";
// Create a new assembly with one module. // Create a new assembly with one module.
#if !MONOTOUCH #if !MONOTOUCH && !SILVERLIGHT
newAssembly = Thread.GetDomain ().DefineDynamicAssembly (assemblyName, AssemblyBuilderAccess.Run); newAssembly = Thread.GetDomain ().DefineDynamicAssembly (assemblyName, AssemblyBuilderAccess.Run);
newModule = newAssembly.DefineDynamicModule ("NLua_generatedcode"); newModule = newAssembly.DefineDynamicModule ("NLua_generatedcode");
#endif #endif
...@@ -95,6 +95,8 @@ namespace NLua ...@@ -95,6 +95,8 @@ namespace NLua
{ {
#if MONOTOUCH #if MONOTOUCH
throw new NotImplementedException (" Emit not available on MonoTouch "); throw new NotImplementedException (" Emit not available on MonoTouch ");
#elif SILVERLIGHT
throw new NotImplementedException(" Emit not available on Silverlight ");
#else #else
string typeName; string typeName;
lock (this) { lock (this) {
...@@ -135,6 +137,8 @@ namespace NLua ...@@ -135,6 +137,8 @@ namespace NLua
{ {
#if MONOTOUCH #if MONOTOUCH
throw new NotImplementedException ("GenerateDelegate is not available on iOS, please register your LuaDelegate type with Lua.RegisterLuaDelegateType( yourDelegate, theLuaDelegateHandler) "); throw new NotImplementedException ("GenerateDelegate is not available on iOS, please register your LuaDelegate type with Lua.RegisterLuaDelegateType( yourDelegate, theLuaDelegateHandler) ");
#elif SILVERLIGHT
throw new NotImplementedException("GenerateDelegate is not available on Silverlight, please register your LuaDelegate type with Lua.RegisterLuaDelegateType( yourDelegate, theLuaDelegateHandler) ");
#else #else
string typeName; string typeName;
lock (this) { lock (this) {
...@@ -314,6 +318,8 @@ namespace NLua ...@@ -314,6 +318,8 @@ namespace NLua
{ {
#if MONOTOUCH #if MONOTOUCH
throw new NotImplementedException (" Emit not available on MonoTouch "); throw new NotImplementedException (" Emit not available on MonoTouch ");
#elif SILVERLIGHT
throw new NotImplementedException (" Emit not available on Silverlight ");
#else #else
string typeName; string typeName;
lock (this) { lock (this) {
...@@ -401,8 +407,13 @@ namespace NLua ...@@ -401,8 +407,13 @@ namespace NLua
for (int i = 0; i < paramTypes.Length; i++) { for (int i = 0; i < paramTypes.Length; i++) {
paramTypes [i] = paramInfo [i].ParameterType; paramTypes [i] = paramInfo [i].ParameterType;
if ((!paramInfo [i].IsIn) && paramInfo [i].IsOut) #if SILVERLIGHT
if (paramInfo[i].IsOut) {
#else
if ((!paramInfo [i].IsIn) && paramInfo [i].IsOut) {
#endif
nOutParams++; nOutParams++;
}
if (paramTypes [i].IsByRef) { if (paramTypes [i].IsByRef) {
returnTypesList.Add (paramTypes [i].GetElementType ()); returnTypesList.Add (paramTypes [i].GetElementType ());
...@@ -413,7 +424,7 @@ namespace NLua ...@@ -413,7 +424,7 @@ namespace NLua
returnTypes = returnTypesList.ToArray (); returnTypes = returnTypesList.ToArray ();
} }
#if !MONOTOUCH #if !MONOTOUCH && !SILVERLIGHT
/* /*
* Generates an overriden implementation of method inside myType that delegates * Generates an overriden implementation of method inside myType that delegates
...@@ -638,6 +649,8 @@ namespace NLua ...@@ -638,6 +649,8 @@ namespace NLua
{ {
#if MONOTOUCH #if MONOTOUCH
throw new NotImplementedException (" Emit not available on MonoTouch "); throw new NotImplementedException (" Emit not available on MonoTouch ");
#elif SILVERLIGHT
throw new NotImplementedException (" Emit not available on Silverlight ");
#else #else
Type eventConsumerType; Type eventConsumerType;
......
...@@ -817,9 +817,9 @@ end ...@@ -817,9 +817,9 @@ end
LuaLib.lua_settop (luaState, oldTop); LuaLib.lua_settop (luaState, oldTop);
} }
public ListDictionary GetTableDict (LuaTable table) public Dictionary<object, object> GetTableDict (LuaTable table)
{ {
var dict = new ListDictionary (); var dict = new Dictionary<object, object> ();
int oldTop = LuaLib.lua_gettop (luaState); int oldTop = LuaLib.lua_gettop (luaState);
translator.push (luaState, table); translator.push (luaState, table);
LuaLib.lua_pushnil (luaState); LuaLib.lua_pushnil (luaState);
......
...@@ -27,7 +27,9 @@ ...@@ -27,7 +27,9 @@
using System; using System;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
#if !SILVERLIGHT
using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization.Formatters.Binary;
#endif
using NLua.Extensions; using NLua.Extensions;
namespace NLua namespace NLua
......
...@@ -27,6 +27,9 @@ using System; ...@@ -27,6 +27,9 @@ using System;
using System.Reflection; using System.Reflection;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using NLua.Extensions; using NLua.Extensions;
#if SILVERLIGHT
using System.Linq;
#endif
namespace NLua namespace NLua
{ {
...@@ -108,8 +111,13 @@ namespace NLua ...@@ -108,8 +111,13 @@ namespace NLua
if (!type.IsEnum) if (!type.IsEnum)
throw new ArgumentException ("The type must be an enumeration!"); throw new ArgumentException ("The type must be an enumeration!");
#if SILVERLIGHT
string[] names = type.GetFields().Where(x => x.IsLiteral).Select(field => field.Name).ToArray();
var values = type.GetFields().Where(x => x.IsLiteral).Select(field => (T)field.GetValue(null)).ToArray();
#else
string[] names = Enum.GetNames (type); string[] names = Enum.GetNames (type);
var values = (T[])Enum.GetValues (type); var values = (T[])Enum.GetValues (type);
#endif
lua.NewTable (type.Name); lua.NewTable (type.Name);
for (int i = 0; i < names.Length; i++) { for (int i = 0; i < names.Length; i++) {
......
...@@ -51,7 +51,7 @@ namespace NLua ...@@ -51,7 +51,7 @@ namespace NLua
{ {
internal LuaCore.lua_CFunction gcFunction, indexFunction, newindexFunction, baseIndexFunction, internal LuaCore.lua_CFunction gcFunction, indexFunction, newindexFunction, baseIndexFunction,
classIndexFunction, classNewindexFunction, execDelegateFunction, callConstructorFunction, toStringFunction; classIndexFunction, classNewindexFunction, execDelegateFunction, callConstructorFunction, toStringFunction;
private Hashtable memberCache = new Hashtable (); private Dictionary<object, object> memberCache = new Dictionary<object, object> ();
private ObjectTranslator translator; private ObjectTranslator translator;
/* /*
...@@ -176,7 +176,11 @@ namespace NLua ...@@ -176,7 +176,11 @@ namespace NLua
strrep = obj.ToString (); strrep = obj.ToString ();
} }
#if WINDOWS_PHONE
Debug.WriteLine("{0}: ({1}) {2}", i, typestr, strrep);
#elif !SILVERLIGHT
Debug.Print ("{0}: ({1}) {2}", i, typestr, strrep); Debug.Print ("{0}: ({1}) {2}", i, typestr, strrep);
#endif
} }
} }
...@@ -470,21 +474,21 @@ namespace NLua ...@@ -470,21 +474,21 @@ 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 (Hashtable memberCache, IReflect objType, string memberName) private object checkMemberCache (Dictionary<object, object> memberCache, IReflect objType, string memberName)
{ {
var members = (Hashtable)memberCache [objType]; var members = (Dictionary<object, object>)memberCache [objType];
return !members.IsNull () ? members [memberName] : null; return !members.IsNull () ? members [memberName] : null;
} }
/* /*
* Stores a MemberInfo object in the member cache. * Stores a MemberInfo object in the member cache.
*/ */
private void setMemberCache (Hashtable memberCache, IReflect objType, string memberName, object member) private void setMemberCache (Dictionary<object, object> memberCache, IReflect objType, string memberName, object member)
{ {
var members = (Hashtable)memberCache [objType]; var members = (Dictionary<object, object>)memberCache[objType];
if (members.IsNull ()) { if (members.IsNull ()) {
members = new Hashtable (); members = new Dictionary<object, object>();
memberCache [objType] = members; memberCache [objType] = members;
} }
...@@ -553,9 +557,11 @@ namespace NLua ...@@ -553,9 +557,11 @@ namespace NLua
} else } else
translator.throwError (luaState, detailMessage); // Pass the original message from trySetMember because it is probably best translator.throwError (luaState, detailMessage); // Pass the original message from trySetMember because it is probably best
} }
#if !SILVERLIGHT
} catch (SEHException) { } catch (SEHException) {
// If we are seeing a C++ exception - this must actually be for Lua's private use. Let it handle it // If we are seeing a C++ exception - this must actually be for Lua's private use. Let it handle it
throw; throw;
#endif
} catch (Exception e) { } catch (Exception e) {
ThrowError (luaState, e); ThrowError (luaState, e);
} }
...@@ -806,14 +812,20 @@ namespace NLua ...@@ -806,14 +812,20 @@ namespace NLua
var paramInfo = method.GetParameters (); var paramInfo = method.GetParameters ();
int currentLuaParam = 1; int currentLuaParam = 1;
int nLuaParams = LuaLib.lua_gettop (luaState); int nLuaParams = LuaLib.lua_gettop (luaState);
var paramList = new ArrayList (); var paramList = new List<object> ();
var outList = new List<int> (); var outList = new List<int> ();
var argTypes = new List<MethodArgs> (); var argTypes = new List<MethodArgs> ();
foreach (var currentNetParam in paramInfo) { foreach (var currentNetParam in paramInfo) {
if (!currentNetParam.IsIn && currentNetParam.IsOut) // Skips out params #if !SILVERLIGHT
outList.Add (paramList.Add (null)); if (!currentNetParam.IsIn && currentNetParam.IsOut) // Skips out params
else if (currentLuaParam > nLuaParams) { // Adds optional parameters #else
if (currentNetParam.IsOut) // Skips out params
#endif
{
paramList.Add (null);
outList.Add (paramList.LastIndexOf (null));
} else if (currentLuaParam > nLuaParams) { // Adds optional parameters
if (currentNetParam.IsOptional) if (currentNetParam.IsOptional)
paramList.Add (currentNetParam.DefaultValue); paramList.Add (currentNetParam.DefaultValue);
else { else {
...@@ -821,7 +833,9 @@ namespace NLua ...@@ -821,7 +833,9 @@ namespace NLua
break; break;
} }
} else if (_IsTypeCorrect (luaState, currentLuaParam, currentNetParam, out extractValue)) { // Type checking } else if (_IsTypeCorrect (luaState, currentLuaParam, currentNetParam, out extractValue)) { // Type checking
int index = paramList.Add (extractValue (luaState, currentLuaParam)); var value = extractValue (luaState, currentLuaParam);
paramList.Add (value);
int index = paramList.LastIndexOf (value);
var methodArg = new MethodArgs (); var methodArg = new MethodArgs ();
methodArg.index = index; methodArg.index = index;
methodArg.extractValue = extractValue; methodArg.extractValue = extractValue;
...@@ -845,7 +859,11 @@ namespace NLua ...@@ -845,7 +859,11 @@ namespace NLua
int paramArrayIndex = 0; int paramArrayIndex = 0;
while (tableEnumerator.MoveNext()) { while (tableEnumerator.MoveNext()) {
#if SILVERLIGHT
paramArray.SetValue (Convert.ChangeType (tableEnumerator.Value, currentNetParam.ParameterType.GetElementType (), System.Globalization.CultureInfo.InvariantCulture), paramArrayIndex);
#else
paramArray.SetValue (Convert.ChangeType (tableEnumerator.Value, currentNetParam.ParameterType.GetElementType ()), paramArrayIndex); paramArray.SetValue (Convert.ChangeType (tableEnumerator.Value, currentNetParam.ParameterType.GetElementType ()), paramArrayIndex);
#endif
paramArrayIndex++; paramArrayIndex++;
} }
} else { } else {
...@@ -853,7 +871,8 @@ namespace NLua ...@@ -853,7 +871,8 @@ namespace NLua
paramArray.SetValue (luaParamValue, 0); paramArray.SetValue (luaParamValue, 0);
} }
int index = paramList.Add (paramArray); paramList.Add (paramArray);
int index = paramList.LastIndexOf (paramArray);
var methodArg = new MethodArgs (); var methodArg = new MethodArgs ();
methodArg.index = index; methodArg.index = index;
methodArg.extractValue = extractValue; methodArg.extractValue = extractValue;
......
...@@ -152,7 +152,11 @@ namespace NLua.Method ...@@ -152,7 +152,11 @@ namespace NLua.Method
paramArray = Array.CreateInstance (paramArrayType, table.Values.Count); paramArray = Array.CreateInstance (paramArrayType, table.Values.Count);
for (int x = 1; x <= table.Values.Count; x++) for (int x = 1; x <= table.Values.Count; x++)
#if SILVERLIGHT
paramArray.SetValue(Convert.ChangeType(table[x], paramArrayType, System.Globalization.CultureInfo.InvariantCulture), x - 1);
#else
paramArray.SetValue (Convert.ChangeType (table [x], paramArrayType), x - 1); paramArray.SetValue (Convert.ChangeType (table [x], paramArrayType), x - 1);
#endif
} else { } else {
paramArray = Array.CreateInstance (paramArrayType, 1); paramArray = Array.CreateInstance (paramArrayType, 1);
paramArray.SetValue (luaParamValue, 0); paramArray.SetValue (luaParamValue, 0);
......
...@@ -44,7 +44,11 @@ namespace NLua.Method ...@@ -44,7 +44,11 @@ namespace NLua.Method
var mi = value as MethodInfo; var mi = value as MethodInfo;
if (!mi.IsNull ()) if (!mi.IsNull ())
#if SILVERLIGHT
IsReturnVoid = string.Compare(mi.ReturnType.Name, "System.Void", StringComparison.InvariantCulture) == 0;
#else
IsReturnVoid = string.Compare (mi.ReturnType.Name, "System.Void", true) == 0; IsReturnVoid = string.Compare (mi.ReturnType.Name, "System.Void", true) == 0;
#endif
} }
} }
......
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.20506</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{380F9E4E-274F-4355-90C1-D196E785F751}</ProjectGuid>
<ProjectTypeGuids>{C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NLua.WP7</RootNamespace>
<AssemblyName>NLua.WP7</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
<TargetFrameworkProfile>WindowsPhone71</TargetFrameworkProfile>
<TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>
<SilverlightApplication>false</SilverlightApplication>
<ValidateXaml>true</ValidateXaml>
<ThrowErrorsInValidation>true</ThrowErrorsInValidation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Bin\Debug</OutputPath>
<DefineConstants>TRACE;DEBUG;SILVERLIGHT;WINDOWS_PHONE;USE_KOPILUA</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>Bin\Release</OutputPath>
<DefineConstants>TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Windows" />
<Reference Include="system" />
<Reference Include="System.Core" />
<Reference Include="System.Xml" />
<Reference Include="System.Net" />
<Reference Include="mscorlib.extensions" />
</ItemGroup>
<ItemGroup>
<Compile Include="CheckType.cs" />
<Compile Include="Config\NLuaConfig.cs" />
<Compile Include="Event\DebugHookEventArgs.cs" />
<Compile Include="Event\EventCodes.cs" />
<Compile Include="Event\EventMasks.cs" />
<Compile Include="Event\HookExceptionEventArgs.cs" />
<Compile Include="Exceptions\LuaException.cs" />
<Compile Include="Exceptions\LuaScriptException.cs" />
<Compile Include="Extensions\GeneralExtensions.cs" />
<Compile Include="GenerateEventAssembly\ClassGenerator.cs" />
<Compile Include="GenerateEventAssembly\CodeGeneration.cs" />
<Compile Include="GenerateEventAssembly\DelegateGenerator.cs" />
<Compile Include="GenerateEventAssembly\ILuaGeneratedType.cs" />
<Compile Include="GenerateEventAssembly\LuaClassType.cs" />
<Compile Include="Lua.cs" />
<Compile Include="LuaBase.cs" />
<Compile Include="LuaFunction.cs" />
<Compile Include="LuaGlobalAttribute.cs" />
<Compile Include="LuaHideAttribute.cs" />
<Compile Include="LuaLib\GCOptions.cs" />
<Compile Include="LuaLib\LuaEnums.cs" />
<Compile Include="LuaLib\LuaIndexes.cs" />
<Compile Include="LuaLib\LuaLib.cs" />
<Compile Include="LuaLib\LuaTypes.cs" />
<Compile Include="LuaLib\References.cs" />
<Compile Include="LuaRegistrationHelper.cs" />
<Compile Include="LuaTable.cs" />
<Compile Include="LuaUserData.cs" />
<Compile Include="Metatables.cs" />
<Compile Include="Method\EventHandlerContainer.cs" />
<Compile Include="Method\LuaClassHelper.cs" />
<Compile Include="Method\LuaDelegate.cs" />
<Compile Include="Method\LuaEventHandler.cs" />
<Compile Include="Method\LuaMethodWrapper.cs" />
<Compile Include="Method\MethodArgs.cs" />
<Compile Include="Method\MethodCache.cs" />
<Compile Include="Method\RegisterEventHandler.cs" />
<Compile Include="ObjectTranslator.cs" />
<Compile Include="ObjectTranslatorPool.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ProxyType.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\KopiLua\KopiLua\KopiLua-wp7.csproj">
<Project>{330E0C63-4160-46E0-BBDA-325185A4AB7A}</Project>
<Name>KopiLua-wp7</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.$(TargetFrameworkProfile).Overrides.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.CSharp.targets" />
<ProjectExtensions />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
...@@ -270,8 +270,10 @@ namespace NLua ...@@ -270,8 +270,10 @@ namespace NLua
// The assemblyName was invalid. It is most likely a path. // The assemblyName was invalid. It is most likely a path.
} }
#if !SILVERLIGHT
if (assembly.IsNull ()) if (assembly.IsNull ())
assembly = Assembly.Load (AssemblyName.GetAssemblyName (assemblyName)); assembly = Assembly.Load (AssemblyName.GetAssemblyName (assemblyName));
#endif
if (!assembly.IsNull () && !assemblies.Contains (assembly)) if (!assembly.IsNull () && !assemblies.Contains (assembly))
assemblies.Add (assembly); assemblies.Add (assembly);
...@@ -777,7 +779,7 @@ namespace NLua ...@@ -777,7 +779,7 @@ namespace NLua
if (oldTop == newTop) if (oldTop == newTop)
return null; return null;
else { else {
var returnValues = new ArrayList (); var returnValues = new List<object> ();
for (int i = oldTop+1; i <= newTop; i++) for (int i = oldTop+1; i <= newTop; i++)
returnValues.Add (getObject (luaState, i)); returnValues.Add (getObject (luaState, i));
...@@ -799,7 +801,7 @@ namespace NLua ...@@ -799,7 +801,7 @@ namespace NLua
return null; return null;
else { else {
int iTypes; int iTypes;
var returnValues = new ArrayList (); var returnValues = new List<object> ();
if (popTypes [0] == typeof(void)) if (popTypes [0] == typeof(void))
iTypes = 1; iTypes = 1;
...@@ -823,7 +825,11 @@ namespace NLua ...@@ -823,7 +825,11 @@ 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).IsNull ());
#else
return (!typ.GetInterface ("ILuaGeneratedType").IsNull ()); return (!typ.GetInterface ("ILuaGeneratedType").IsNull ());
#endif
} else } else
return false; return false;
} }
......

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010 Express for Windows Phone
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NLua.WP7", "Core\NLua\NLua.WP7.csproj", "{380F9E4E-274F-4355-90C1-D196E785F751}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KopiLua-wp7", "Core\KopiLua\KopiLua\KopiLua-wp7.csproj", "{330E0C63-4160-46E0-BBDA-325185A4AB7A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{380F9E4E-274F-4355-90C1-D196E785F751}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{380F9E4E-274F-4355-90C1-D196E785F751}.Debug|Any CPU.Build.0 = Debug|Any CPU
{380F9E4E-274F-4355-90C1-D196E785F751}.Release|Any CPU.ActiveCfg = Release|Any CPU
{380F9E4E-274F-4355-90C1-D196E785F751}.Release|Any CPU.Build.0 = Release|Any CPU
{330E0C63-4160-46E0-BBDA-325185A4AB7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{330E0C63-4160-46E0-BBDA-325185A4AB7A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{330E0C63-4160-46E0-BBDA-325185A4AB7A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{330E0C63-4160-46E0-BBDA-325185A4AB7A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
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