Exemplo n.º 1
0
        public static ApiObjectPrototype CreatePrototypeObject(CpuBlock block, ApiObjectConstructor constructor, List <CpuApiProperty> props)
        {
            var obj = new ApiObjectPrototype(block, props)
            {
                _prototype   = block.Interp.Object.PrototypeObject,
                _constructor = constructor
            };

            return(obj);
        }
Exemplo n.º 2
0
        public static ApiObjectConstructor CreateApiConstructor(CpuBlock cpu, string name, List <CpuApiProperty> staticProps, List <CpuApiProperty> instanceProps)
        {
            var obj = new ApiObjectConstructor(cpu, name, staticProps)
            {
                _prototype = cpu.Interp.Function.PrototypeObject,
            };

            obj.PrototypeObject      = ApiObjectPrototype.CreatePrototypeObject(cpu, obj, instanceProps);
            obj._prototypeDescriptor = new PropertyDescriptor(obj.PrototypeObject, PropertyFlag.AllForbidden);
            return(obj);
        }
Exemplo n.º 3
0
        public void Attach(CpuBlock block)
        {
            foreach (var api in RootApi)
            {
                block.Interp.SetValue(api.Key, (t, a) => api.Value.Implementation(block, t, a));
            }

            foreach (var kp in ApiNamespaces)
            {
                var obj = block.Interp.Global.Get(kp.Key) as ObjectInstance;
                if (obj != null)
                {
                    throw new Exception($"Runtime error: namespace {kp.Key} already exists");
                }

                obj = ApiObjectConstructor.CreateApiConstructor(block, kp.Key, kp.Value.StaticFields, kp.Value.InstanceFields);
                block.Interp.Global.Set(kp.Key, obj);
            }
            // Legacy crutch
            var math = block.Interp.Global.Get("Math") as ObjectInstance;

            math.Set("newton", block.Interp.Global.Get("MathExt").Get("newton"));
        }