예제 #1
0
        public static IWorker wrap(double value)
        {
            Client_Rational o = new Client_Rational(value);
            NObject obj = new NObject();
            WorkerBuilder builder = new WorkerBuilder(
            Bridge.stdn_Rat, obj, new IWorker[]{} );

            builder.addBreeder(
            Bridge.stdn_String,
            delegate(){
                return Bridge.toClientString(
                    value.ToString().ToLower());
            });

            builder.addMethod(
            new Identifier("add"),
            new Function_Native(
                new ParameterImpl[]{
                    new ParameterImpl(
                        Direction.IN,
                        new NType(Bridge.stdn_Rat),
                        new Identifier("value"),
                        null )
                },
                new NType(Bridge.stdn_Rat),
                delegate(IScope args) {
                    return Bridge.toClientRational(
                            o.add(
                                Bridge.toNativeRational(
                                    GE.evalIdent(args, "value"))));
                },
                null ));

            builder.addMethod(
            new Identifier("lessThan?"),
            new Function_Native(
                new ParameterImpl[]{
                    new ParameterImpl(
                        Direction.IN,
                        new NType(Bridge.stdn_Rat),
                        new Identifier("value"),
                        null )
                },
                new NType(Bridge.stdn_Bool),
                delegate(IScope args) {
                    return Bridge.toClientBoolean(
                            o.lessThan(
                                Bridge.toNativeRational(
                                    GE.evalIdent(args, "value"))));
                },
                null ));

            IWorker rv = builder.compile();
            rv.nativeObject = value;
            obj.rootWorker = rv;
            return rv;
        }
예제 #2
0
        public static IWorker wrap(IList<uint> codePoints)
        {
            Client_String o = new Client_String(codePoints);
            NObject obj = new NObject();
            WorkerBuilder builder = new WorkerBuilder(
            Bridge.stdn_String, obj, new IWorker[]{});

            builder.addBreeder(
            Bridge.stdn_String,
            delegate(){ return wrap(codePoints); });

            builder.addPropertyGetter(
            new Identifier("length"),
            delegate(){ return Bridge.toClientInteger(o.length); });

            builder.addMethod(
            new Identifier("concat"),
            new Function_Native(
                new ParameterImpl[]{
                    new ParameterImpl(
                        Direction.IN,
                        new NType(Bridge.stdn_String),
                        new Identifier("value"),
                        null )
                },
                new NType(Bridge.stdn_String),
                delegate(IScope args) {
                    return wrap(
                        o.concat(
                            unwrap(
                                GE.evalIdent(args, "value"))));
                },
                null ));

            builder.addMethod(
            new Identifier("concat!"),
            new Function_Native(
                new ParameterImpl[]{
                    new ParameterImpl(
                        Direction.IN,
                        new NType(Bridge.stdn_String),
                        new Identifier("value"),
                        null )
                },
                null,
                delegate(IScope args) {
                    o.concat0(
                        unwrap(
                            GE.evalIdent(args, "value")));
                    return wrap(o._codePoints);
                },
                null ));

            builder.addMethod(
            new Identifier("substring"),
            new Function_Native(
                new ParameterImpl[]{
                    new ParameterImpl(
                        Direction.IN,
                        new NType(Bridge.stdn_Int),
                        new Identifier("start"),
                        null )
                },
                new NType(Bridge.stdn_String),
                delegate(IScope args) {
                    return wrap(
                            o.substring(
                                Bridge.toNativeInteger(
                                    GE.evalIdent(args, "start"))));
                },
                null ));

            builder.addMethod(
            new Identifier("substring"),
            new Function_Native(
                new ParameterImpl[]{
                    new ParameterImpl(
                        Direction.IN,
                        new NType(Bridge.stdn_Int),
                        new Identifier("start"),
                        null ),
                    new ParameterImpl(
                        Direction.IN,
                        new NType(Bridge.stdn_Int),
                        new Identifier("limit"),
                        null )
                },
                new NType(Bridge.stdn_String),
                delegate(IScope args) {
                    return wrap(
                            o.substring(
                                Bridge.toNativeInteger(
                                    GE.evalIdent(args, "start")),
                                Bridge.toNativeInteger(
                                    GE.evalIdent(args, "limit"))));
                },
                null ));

            IWorker rv = builder.compile();
            rv.nativeObject = codePoints;
            obj.rootWorker = rv;
            return rv;
        }