예제 #1
0
        public SkryptObject GetPropertiesFrom(SkryptObject Object)
        {
            //Properties = new List<SkryptProperty>(Object.Properties);

            foreach (var p in Object.Properties)
            {
                var property = new SkryptProperty {
                    Name      = p.Name,
                    Modifiers = p.Modifiers
                };

                if (typeof(SkryptType).IsAssignableFrom(p.Value.GetType()))
                {
                    property.Value = ((SkryptType)p.Value).CreateCopyOnAssignment ? p.Value.Copy() : p.Value;
                }
                else
                {
                    property.Value = p.Value;
                }

                Properties.Add(property);
            }

            return(this);
        }
예제 #2
0
        public override ScopeContext Execute(SkryptEngine engine, SkryptObject self, SkryptObject[] parameters, ScopeContext scope)
        {
            var inputScope = new ScopeContext {
                ParentScope = scope,
                Properties  = scope.Properties | ScopeProperties.InMethod,
                CallStack   = scope.CallStack
            };

            if (self == null && Class != null)
            {
                inputScope.SetVariable("self", Class, Modifier.Const);
            }
            else if (self != null)
            {
                inputScope.SetVariable("self", self, Modifier.Const);
            }

            var resultingScope = engine.Executor.ExecuteBlock(BlockNode, inputScope);

            resultingScope.ReturnObject = resultingScope.ReturnObject ?? new Native.System.Null();
            resultingScope.Variables    = new Dictionary <string, Variable>(scope.Variables);

            resultingScope.ReturnObject.Engine = Engine;

            return(resultingScope);
        }
예제 #3
0
        public override ScopeContext Execute(SkryptEngine engine, SkryptObject self, SkryptObject[] parameters, ScopeContext scope)
        {
            SkryptObject returnValue = null;

            if (IsSkryptMethod)
            {
                returnValue = ((SkryptDelegate)Method)(engine, self, parameters);
            }
            else
            {
                var parCount = Method.Method.GetParameters().Count();

                var input = new object[parCount];

                for (int i = 0; i < input.Length; i++)
                {
                    if (i < parameters.Length)
                    {
                        input[i] = parameters[i];
                    }
                    else
                    {
                        input[i] = null;
                    }
                }

                returnValue = (SkryptObject)Method.DynamicInvoke(input);

                if (returnValue == null)
                {
                    returnValue = engine.Create <Null>();
                }
            }

            if (typeof(SkryptType).IsAssignableFrom(returnValue.GetType()))
            {
                returnValue.GetPropertiesFrom(engine.Executor.GetType(((SkryptType)returnValue).TypeName, scope));
            }

            var newScope = new ScopeContext {
                ParentScope = scope,
                Properties  = scope.Properties | ScopeProperties.InMethod
            };

            if (self != null)
            {
                newScope.SetVariable("self", self, Modifier.Const);
            }

            newScope.ReturnObject        = returnValue;
            newScope.ReturnObject.Engine = engine;
            newScope.Variables           = new Dictionary <string, Variable>(scope.Variables);

            return(newScope);
        }
예제 #4
0
        public static string GetString(SkryptObject o, SkryptEngine engine)
        {
            var s  = o.ToString();
            var ts = o.GetProperty("ToString");

            if (ts != null && typeof(UserFunction).IsAssignableFrom(ts.GetType()))
            {
                s = ((UserFunction)ts).Execute(engine, o, null, engine.CurrentScope).ReturnObject.ToString();
            }

            return(s);
        }
예제 #5
0
        public override SkryptObject Execute(SkryptEngine engine, SkryptObject[] parameters, ScopeContext scope)
        {
            ScopeContext ResultingScope = engine.executor.ExecuteBlock(BlockNode, scope, new SubContext {
                InMethod = true, Method = this
            });

            SkryptObject ReturnVariable = ResultingScope.subContext.ReturnObject;

            if (ReturnVariable == null)
            {
                ReturnVariable = new Native.System.Void();
            }

            return(ReturnVariable);
        }
예제 #6
0
        public override ScopeContext Execute(SkryptEngine engine, SkryptObject self, SkryptObject[] parameters, ScopeContext scope)
        {
            var returnValue = Method(self, parameters);

            if (typeof(SkryptType).IsAssignableFrom(returnValue.GetType()))
            {
                returnValue.GetPropertiesFrom(engine.Executor.GetType(((SkryptType)returnValue).TypeName, scope));
            }

            var newScope = new ScopeContext {
                ParentScope = scope,
                Properties  = scope.Properties
            };

            newScope.ReturnObject        = returnValue;
            newScope.ReturnObject.Engine = engine;
            newScope.Variables           = new Dictionary <string, Variable>(scope.Variables);

            return(newScope);
        }
예제 #7
0
 public void SetProperty(string name, SkryptObject value)
 {
     Properties.Find(x => x.Name == name).Value = value;
 }
예제 #8
0
 public virtual ScopeContext Execute(SkryptEngine engine, SkryptObject self, SkryptObject[] parameters, ScopeContext scope)
 {
     return(null);
 }
예제 #9
0
 public void Execute(SkryptEngine engine, SkryptObject self, SkryptObject value,
                     ScopeContext scope)
 {
     Method(self, value);
 }