Ejemplo n.º 1
0
        public IoCLRFunction getMethod(IoMessage message)
        {
            string methodName = message.messageName.value;

            if (clrType == null)
            {
                return(null);
            }
            ConstructorInfo[] searchConstructors = null;
            Type[]            parameters         = null;
            ArrayList         args = null;
            MethodBase        mb   = null;

            args       = new ArrayList();
            parameters = new Type[message.args.Count];

            for (int i = 0; i < message.args.Count; i++)
            {
                IoObject o = message.localsValueArgAt(message, i);
                args.Add(o);
                Type t = null;
                switch (o.name)
                {
                case "Number": t = typeof(double); break;

                case "Object": t = typeof(object); break;

                case "CLRObject": t = (o as IoCLRObject).clrType; break;

                case "Sequence": t = typeof(string); break;
                }
                parameters[i] = t;
            }

            if (methodName.Equals("new"))
            {
                searchConstructors = this.clrType.GetConstructors();
                if (searchConstructors.Length > 0)
                {
                    mb = searchConstructors[0];
                }
            }
            else
            {
                try
                {
                    mb = this.clrType.GetMethod(methodName, parameters);
                }
                catch { }
            }

            IoCLRFunction clrFunction = IoCLRFunction.createObject(this.state);

            clrFunction.methodInfo          = mb;
            clrFunction.parametersTypes     = parameters;
            clrFunction.evaluatedParameters = args;
            return(clrFunction);
        }
Ejemplo n.º 2
0
        public override IoObject proto(IoState state)
        {
            IoCLRFunction pro = new IoCLRFunction();

            pro.state    = state;
            pro.uniqueId = 0;
            pro.createSlots();
            pro.createProtos();
            pro.isActivatable = true;
            state.registerProtoWithFunc(pro.name, new IoStateProto(pro.name, pro, new IoStateProtoFunc(pro.proto)));
            //pro.protos.Add(state.protoWithInitFunc("Object"));

            IoCFunction[] methodTable = new IoCFunction[] {
            };

            pro.addTaglessMethodTable(state, methodTable);
            return(pro);
        }
Ejemplo n.º 3
0
 public static new IoCLRFunction createProto(IoState state)
 {
     IoCLRFunction cf = new IoCLRFunction();
     return cf.proto(state) as IoCLRFunction;
 }
Ejemplo n.º 4
0
 public static new IoCLRFunction createObject(IoState state)
 {
     IoCLRFunction cf = new IoCLRFunction();
     return cf.proto(state).clone(state) as IoCLRFunction;
 }
Ejemplo n.º 5
0
        public override IoObject proto(IoState state)
        {
            IoCLRFunction pro = new IoCLRFunction();
            pro.state = state;
            pro.uniqueId = 0;
            pro.createSlots();
            pro.createProtos();
            pro.isActivatable = true;
            state.registerProtoWithFunc(pro.name, new IoStateProto(pro.name, pro, new IoStateProtoFunc(pro.proto)));
            //pro.protos.Add(state.protoWithInitFunc("Object"));

            IoCFunction[] methodTable = new IoCFunction[] {
            };

            pro.addTaglessMethodTable(state, methodTable);
            return pro;
        }
Ejemplo n.º 6
0
        public override IoObject activate(IoObject self, IoObject target, IoObject locals, IoMessage m, IoObject slotContext)
        {
            IoCLRFunction method = self as IoCLRFunction;
            IoCLRObject   obj    = target as IoCLRObject;
            object        result = null;

            object[] parameters = new object[method.evaluatedParameters.Count];
            for (int i = 0; i < method.evaluatedParameters.Count; i++)
            {
                IoObject ep = method.evaluatedParameters[i] as IoObject;
                switch (ep.name)
                {
                case "Object": parameters[i] = ep; break;

                case "Number":
                {
                    IoNumber num = ep as IoNumber;
                    if (num.isInteger)
                    {
                        parameters[i] = num.longValue;
                    }
                    else
                    {
                        parameters[i] = num.doubleValue;
                    }
                }
                break;

                case "Sequence": parameters[i] = (ep as IoSeq).value; break;

                case "CLRObject": parameters[i] = (ep as IoCLRObject).clrInstance; break;
                }
            }

            IoCLRObject clr = IoCLRObject.createObject(self.state);

            try
            {
                if (method.methodInfo is ConstructorInfo)
                {
                    ConstructorInfo ci = method.methodInfo as ConstructorInfo;
                    result = ci.Invoke(parameters);
                }
                else if (method.methodInfo is MethodInfo)
                {
                    MethodInfo mi = method.methodInfo as MethodInfo;
                    result = mi.Invoke(obj.clrInstance, parameters);
                }
                clr.clrType = result != null?result.GetType() : null;

                clr.clrInstance = result;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
                clr.clrType     = null;
                clr.clrInstance = null;
            }

            return(clr);
        }
Ejemplo n.º 7
0
        public new static IoCLRFunction createObject(IoState state)
        {
            IoCLRFunction cf = new IoCLRFunction();

            return(cf.proto(state).clone(state) as IoCLRFunction);
        }
Ejemplo n.º 8
0
        public new static IoCLRFunction createProto(IoState state)
        {
            IoCLRFunction cf = new IoCLRFunction();

            return(cf.proto(state) as IoCLRFunction);
        }