Ejemplo n.º 1
0
        public override string ToString()
        {
            var s = new StringBuilder();

            s.Append(GetType().FullName).Append(": ").Append(Message);
            if (Value != null)
            {
                s.Append(" [").Append(Value.ToString()).Append("]");
            }
            s.AppendLine();
            for (int i = 0; i < TracebackArray.Length; i++)
            {
                s.Append("  ").AppendLine(TracebackArray [i]);
            }
            return(s.ToString());
        }
Ejemplo n.º 2
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());
                }
            }
Ejemplo n.º 3
0
 public LuaException(string message, Exception inner, LuaValue value = null, string traceback = null) : base(value?.ToString() ?? message, inner)
 {
     tracebackString   = traceback;
     tracebackHashCode = -1;
     Value             = value;
 }