public Delegate GetDelegate(Type delegateType, LuaFunction luaFunc)
{
List<Type> returnTypes=new List<Type>();
Type luaDelegateType;
if (delegateCollection.ContainsKey(delegateType))
{
luaDelegateType=delegateCollection[delegateType];
}
else
{
luaDelegateType=GenerateDelegate(delegateType);
delegateCollection[delegateType] = luaDelegateType;
}
MethodInfo methodInfo=delegateType.GetMethod("Invoke");
returnTypes.Add(methodInfo.ReturnType);
foreach(ParameterInfo paramInfo in methodInfo.GetParameters())
if(paramInfo.ParameterType.IsByRef)
returnTypes.Add(paramInfo.ParameterType);
LuaDelegate luaDelegate=(LuaDelegate)Activator.CreateInstance(luaDelegateType);
luaDelegate.function=luaFunc;
luaDelegate.returnTypes=returnTypes.ToArray();
return Delegate.CreateDelegate(delegateType,luaDelegate,"CallFunction");
}