Beispiel #1
0
            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());
                }
            }
Beispiel #2
0
 public override bool Equals(LuaValue other)
 {
     return(Equals(other as LuaClrTypeObject));
 }
Beispiel #3
0
 public override bool Contains(LuaValue item)
 {
     return(Table.ContainsKey(item));
 }
 public override bool Equals(LuaValue other)
 {
     return(Equals(other as LuaOpaqueClrObject));
 }
Beispiel #5
0
 public LuaException(string message, Exception inner, LuaValue value = null, string traceback = null) : base(value?.ToString() ?? message, inner)
 {
     tracebackString   = traceback;
     tracebackHashCode = -1;
     Value             = value;
 }
Beispiel #6
0
 public override bool Equals(LuaValue other)
 {
     return(Equals(other as LuaString));
 }
 public override bool Equals(LuaValue other)
 {
     return(Equals(other as LuaTransparentClrObject));
 }
Beispiel #8
0
 public override bool Equals(LuaValue other)
 {
     return(Equals(other as LuaNumber));
 }
Beispiel #9
0
 public override bool Equals(LuaValue other)
 {
     return(Equals(other as LuaReference));
 }
Beispiel #10
0
 public static bool IsNil(this LuaValue self)
 {
     return(self == null || self == LuaNil.Instance);
 }
Beispiel #11
0
 public override bool Equals(LuaValue other)
 {
     return(Equals(other as LuaBoolean));
 }