public LuaValue this [LuaRuntime runtime, LuaValue keyValue] { get { var members = GetMembers(keyValue); if (members.Count == 1) { var method = members [0] as MethodInfo; if (method != null) { return(runtime.CreateFunctionFromMethodWrapper(new LuaRuntime.MethodWrapper(type, method, @static: true))); } var property = members [0] as PropertyInfo; if (property != null) { var getter = property.GetGetMethod(); if (getter == null) { throw new LuaException("Property is write-only."); } if (getter.GetParameters().Length != 0) { throw new LuaException("Cannot get an indexer."); } var ret = property.GetValue(type, null); return(clrObject.Binder.ObjectToLuaValue(ret, clrObject, runtime)); } var field = members [0] as FieldInfo; if (field != null) { return(clrObject.Binder.ObjectToLuaValue(field.GetValue(type), clrObject, runtime)); } } return(LuaNil.Instance); } set { var members = GetMembers(keyValue); if (members.Count == 1) { var property = members [0] as PropertyInfo; if (property != null) { var setter = property.GetSetMethod(); if (setter == null) { throw new LuaException("Property is read-only."); } if (setter.GetParameters().Length != 1) { throw new LuaException("Cannot set an indexer."); } object v; try { v = value.ToClrType(property.PropertyType); } catch { throw new LuaException("Value is incompatible with this property."); } property.SetValue(null, v, null); return; } var field = members [0] as FieldInfo; if (field != null) { object v; try { v = value.ToClrType(field.FieldType); } catch { throw new LuaException("Value is incompatible with this property."); } field.SetValue(null, v); return; } } throw new LuaException("Property/field not found: " + keyValue.ToString()); } }
public override bool Equals(LuaValue other) { return(Equals(other as LuaClrTypeObject)); }
public override bool Contains(LuaValue item) { return(Table.ContainsKey(item)); }
public override bool Equals(LuaValue other) { return(Equals(other as LuaOpaqueClrObject)); }
public LuaException(string message, Exception inner, LuaValue value = null, string traceback = null) : base(value?.ToString() ?? message, inner) { tracebackString = traceback; tracebackHashCode = -1; Value = value; }
public override bool Equals(LuaValue other) { return(Equals(other as LuaString)); }
public override bool Equals(LuaValue other) { return(Equals(other as LuaTransparentClrObject)); }
public override bool Equals(LuaValue other) { return(Equals(other as LuaNumber)); }
public override bool Equals(LuaValue other) { return(Equals(other as LuaReference)); }
public static bool IsNil(this LuaValue self) { return(self == null || self == LuaNil.Instance); }
public override bool Equals(LuaValue other) { return(Equals(other as LuaBoolean)); }