public StringPrototype(MelonEngine engine, MelonType type) : base(engine, type)
        {
            var properties = new PropertyDictionary {
                ["Length"] = new Property(new NativeFunctionInstance("Length", type, engine, Length))
            };

            SetProperties(properties);
        }
        public LexicalEnvironment(MelonEngine engine, bool isRoot)
        {
            IsRoot = isRoot;

            _engine = engine;

            Children = new List <LexicalEnvironment>();
        }
        public LexicalEnvironment(LexicalEnvironment parent, bool isRoot)
        {
            IsRoot = isRoot;
            Parent = parent;

            Parent.AddChild(this);
            _engine = Parent._engine;

            Variables = new Dictionary <string, Variable>();
            Children  = new List <LexicalEnvironment>();
        }
示例#4
0
        public NativeFunctionInstance(string name, MelonObject self, MelonEngine engine, NativeFunctionDelegate del) : base(name, engine)
        {
            Self = self;

            ReturnTypeAttribute returnTypeAttribute = del.Method.GetCustomAttribute <ReturnTypeAttribute>();

            if (returnTypeAttribute != null)
            {
                ReturnType = new TypeReference(engine, engine.GetType(returnTypeAttribute.Type));
            }

            ParameterAttribute[] parameterAttributes = del.Method.GetCustomAttributes <ParameterAttribute>().ToArray();

            if (parameterAttributes?.Length > 0)
            {
                ParameterTypes = new FunctionParameter[parameterAttributes.Length];

                bool hasVarargs = false;

                for (int i = 0; i < parameterAttributes.Length; i++)
                {
                    if (parameterAttributes[i].IsGeneric)
                    {
                        ParameterTypes[i] = new FunctionParameter(parameterAttributes[i].Name, parameterAttributes[i].GenericIndex);
                    }
                    else
                    {
                        ParameterTypes[i] = new FunctionParameter(parameterAttributes[i].Name, new TypeReference(engine, engine.GetType(parameterAttributes[i].Type)));
                    }

                    if (parameterAttributes[i].IsVarargs)
                    {
                        if (hasVarargs || i < parameterAttributes.Length - 1)
                        {
                            throw new MelonException("Varargs parameter can only appear once and has to be the last parameter");
                        }

                        ParameterTypes[i].IsVarargs = true;

                        hasVarargs = true;
                    }
                }
            }
            else
            {
                ParameterTypes = new[] { new FunctionParameter("", new TypeReference(engine, engine.anyType))
                                         {
                                             IsVarargs = true
                                         } };
            }

            Delegate = del;
        }
示例#5
0
        public static bool TryCreateFunction(MelonEngine engine, MethodInfo method, out NativeFunctionInstance function)
        {
            if (CheckSignature(method))
            {
                var del = (NativeFunctionDelegate)method.CreateDelegate(typeof(NativeFunctionDelegate));

                function = new NativeFunctionInstance(del.Method.Name, null, engine, del);

                return(true);
            }

            function = null;

            return(false);
        }
示例#6
0
 public BooleanType(MelonEngine engine) : base(engine)
 {
 }
示例#7
0
 public FunctionInstance(string name, MelonEngine engine) : base(engine)
 {
     Type = engine.functionType;
     Name = name;
 }
 public FunctionType(MelonEngine engine) : base(engine)
 {
     Prototype = new FunctionPrototype(engine, this);
 }
示例#9
0
 public AnyType(MelonEngine engine) : base(engine)
 {
 }
示例#10
0
 public ParseContext(MelonEngine engine, LexicalEnvironment environment)
 {
     LexicalEnvironment = new LexicalEnvironment(environment, !environment.IsRoot);
 }
示例#11
0
 public MelonType(MelonEngine engine) : base(engine)
 {
 }
 public MelonPrototype(MelonEngine engine, MelonType type) : base(engine)
 {
     Type = type;
 }
 public MelonGenericType(MelonEngine engine) : base(engine)
 {
 }
示例#14
0
 public ByteCodePrinter(MelonEngine engine)
 {
     _engine = engine;
 }
示例#15
0
 public MelonInstance(MelonEngine engine) : base(engine)
 {
 }
示例#16
0
 public MelonVisitor(MelonEngine engine, ScriptFunctionInstance scriptFunction) : this(engine) {
     _scriptFunction = scriptFunction;
 }
 public BooleanPrototype(MelonEngine engine, MelonType type) : base(engine, type)
 {
 }
 public FunctionPrototype(MelonEngine engine, MelonType type) : base(engine, type)
 {
 }
示例#19
0
        public BooleanInstance(MelonEngine engine, bool val) : base(engine)
        {
            Type = engine.booleanType;

            value = val;
        }
 public ExpressionSolver(MelonEngine engine)
 {
     _engine = engine;
 }
示例#21
0
 public FloatPrototype(MelonEngine engine, MelonType type) : base(engine, type)
 {
 }
        public IntegerInstance(MelonEngine engine, int val) : base(engine)
        {
            Type = engine.integerType;

            value = val;
        }
示例#23
0
 public FloatType(MelonEngine engine) : base(engine)
 {
 }
示例#24
0
 public IntegerPrototype(MelonEngine engine, MelonType type) : base(engine, type)
 {
 }
        public MelonInterpreter(MelonEngine engine)
        {
            _engine = engine;

            _expressionSolver = new ExpressionSolver(engine);
        }
示例#26
0
        public FloatInstance(MelonEngine engine, double val) : base(engine)
        {
            Type = engine.floatType;

            value = val;
        }
示例#27
0
        public ArrayInstance(MelonEngine engine, MelonObject[] vals) : base(engine)
        {
            Type = engine.arrayType;

            values = new List <MelonObject>(vals);
        }
示例#28
0
 public IntegerType(MelonEngine engine) : base(engine)
 {
 }
示例#29
0
 public MelonErrorObject(MelonEngine engine, string msg) : base(engine)
 {
     message = msg;
 }
示例#30
0
 public MelonVisitor(MelonEngine engine)
 {
     _engine           = engine;
     _expressionSolver = new ExpressionSolver(engine);
 }