public static int setFieldOrProperty(IntPtr luaState)
{
ObjectTranslator objectTranslator = ObjectTranslator.FromState(luaState);
object rawNetObject = objectTranslator.getRawNetObject(luaState, 1);
if (rawNetObject == null)
{
objectTranslator.throwError(luaState, "trying to index and invalid object reference");
return(0);
}
Type type = rawNetObject.GetType();
string message;
bool flag = objectTranslator.metaFunctions.trySetMember(luaState, type, rawNetObject, BindingFlags.IgnoreCase | BindingFlags.Instance, out message);
if (flag)
{
return(0);
}
try
{
if (type.IsArray && LuaDLL.lua_isnumber(luaState, 2))
{
int index = (int)LuaDLL.lua_tonumber(luaState, 2);
Array array = (Array)rawNetObject;
object asType = objectTranslator.getAsType(luaState, 3, array.GetType().GetElementType());
array.SetValue(asType, index);
}
else
{
MethodInfo method = type.GetMethod("set_Item");
if (method != null)
{
ParameterInfo[] parameters = method.GetParameters();
Type parameterType = parameters[1].ParameterType;
object asType2 = objectTranslator.getAsType(luaState, 3, parameterType);
Type parameterType2 = parameters[0].ParameterType;
object asType3 = objectTranslator.getAsType(luaState, 2, parameterType2);
method.Invoke(rawNetObject, new object[]
{
asType3,
asType2
});
}
else
{
objectTranslator.throwError(luaState, message);
}
}
}
catch (SEHException)
{
throw;
}
catch (Exception e)
{
objectTranslator.metaFunctions.ThrowError(luaState, e);
}
return(0);
}