Examples of GlobalVariables


Examples of org.jruby.internal.runtime.GlobalVariables

        return result;
    }  

    private synchronized Node compileScript(String script, ScriptContext ctx)
                                 throws ScriptException {       
        GlobalVariables oldGlobals = runtime.getGlobalVariables()
        try {
            setGlobalVariables(ctx);
            String filename = (String) ctx.getAttribute(ScriptEngine.FILENAME);
            if (filename == null) {
                filename = "<unknown>";
View Full Code Here

Examples of org.jruby.internal.runtime.GlobalVariables

        }
    }

    private synchronized Node compileScript(Reader reader, ScriptContext ctx)
                                 throws ScriptException {       
        GlobalVariables oldGlobals = runtime.getGlobalVariables()
        try {
            setGlobalVariables(ctx);
            String filename = (String) ctx.getAttribute(ScriptEngine.FILENAME);
            if (filename == null) {
                filename = "<unknown>";
View Full Code Here

Examples of org.jruby.internal.runtime.GlobalVariables

        }
    }

    private void setGlobalVariables(final ScriptContext ctx) {
        ctx.setAttribute("context", ctx, ScriptContext.ENGINE_SCOPE);
        setGlobalVariables(new GlobalVariables(runtime) {
                GlobalVariables parent = runtime.getGlobalVariables();
               
                @Override
                public void define(String name, IAccessor accessor) {
                    assert name != null;
View Full Code Here

Examples of org.jruby.internal.runtime.GlobalVariables

        runtime.setGlobalVariables(globals);
    }

    private synchronized Object evalNode(Node node, ScriptContext ctx)
                            throws ScriptException {
        GlobalVariables oldGlobals = runtime.getGlobalVariables();
        try {
            setGlobalVariables(ctx);
            return rubyToJava(runtime.eval(node));
        } catch (RaiseException exp) {
            RubyException rexp = exp.getException();
View Full Code Here

Examples of org.jruby.internal.runtime.GlobalVariables

     * @param vars map to save retrieved global variables.
     */
    public static void retrieve(RubyObject receiver, BiVariableMap vars) {
        if (vars.isLazy()) return;
       
        GlobalVariables gvars = receiver.getRuntime().getGlobalVariables();
        Set<String> names = gvars.getNames();
        for (String name : names) {
            if (isPredefined(name)) {
                continue;
            }
            IRubyObject value = gvars.get(name);
            String javaName = name.substring(1); // eliminates a preceding character, "$"
            updateLocalGlobal((RubyObject)receiver.getRuntime().getTopSelf(), vars, javaName, value);
        }
    }
View Full Code Here

Examples of org.jruby.internal.runtime.GlobalVariables

     * @param runtime Ruby runtime
     * @param vars map to save a retrieved global variable.
     * @param key name of the global variable
     */
    public static void retrieveByKey(Ruby runtime, BiVariableMap vars, String key) {
        GlobalVariables gvars = runtime.getGlobalVariables();
        // if the specified key doesn't exist, this method is called before the
        // evaluation. Don't update value in this case.
        String rubyKey = ("$" + key).intern();
        if (!gvars.getNames().contains(rubyKey)) return;

        // the specified key is found, so let's update
        IRubyObject value = gvars.get(rubyKey);
        updateLocalGlobal((RubyObject)runtime.getTopSelf(), vars, key, value);
    }
View Full Code Here

Examples of org.jruby.internal.runtime.GlobalVariables

     * @param receiver receiver object returned when a script is evaluated.
     * @param vars map to save retrieved global variables.
     */
    public static void retrieve(IRubyObject receiver, BiVariableMap vars) {
        if (vars.isLazy()) return;
        GlobalVariables gvars = receiver.getRuntime().getGlobalVariables();
        Set<String> names = gvars.getNames();
        for (String name : names) {
            if (isPredefined(name)) {
                continue;
            }
            IRubyObject value = gvars.get(name);
            // reciever of gvar should to topSelf always
            updateGlobalVar(vars, (RubyObject)receiver.getRuntime().getTopSelf(), name, value);
        }
    }
View Full Code Here

Examples of org.jruby.internal.runtime.GlobalVariables

     * @param receiver receiver object returned when a script is evaluated.
     * @param vars map to save a retrieved global variable.
     * @param key name of the global variable
     */
    public static void retrieveByKey(Ruby runtime, BiVariableMap vars, String key) {
        GlobalVariables gvars = runtime.getGlobalVariables();
        // if the specified key doesn't exist, this method is called before the
        // evaluation. Don't update value in this case.
        if (!gvars.getNames().contains(key)) return;

        // the specified key is found, so let's update
        IRubyObject value = gvars.get(key);
        updateGlobalVar(vars, (RubyObject)runtime.getTopSelf(), key, value);
    }
View Full Code Here

Examples of org.jruby.internal.runtime.GlobalVariables

        for (int i = 0; i < lineCount; i++)
            lineNumbers[i] = i;

        // Don'
        Ruby runtime = container.getProvider().getRuntime();
        GlobalVariables gvars = runtime.getGlobalVariables();
        IRubyObject orig = gvars.get("$stderr");
        // Todo: cache this or find a better way of supressing output...
        gvars.set("$stderr", new RubyIO(runtime, new ByteArrayOutputStream()));
        try {
            return container.parse(scr, lineNumbers);
        } catch (ParseFailedException e) {
            /**/
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            gvars.set("$stderr", orig);
        }
        return null;
    }
View Full Code Here

Examples of org.jruby.internal.runtime.GlobalVariables

        DefaultParseResult dpr = new DefaultParseResult(this);
        dpr.setParsedLines(0, lineCount);

        // Suppress output...
        Ruby runtime = container.getProvider().getRuntime();
        GlobalVariables gvars = runtime.getGlobalVariables();
        IRubyObject orig = gvars.get("$stderr");
        // Todo: cache this or find a better way of supressing output...
        gvars.set("$stderr", new RubyIO(runtime, new ByteArrayOutputStream()));
        try {
            container.parse(scr, lineNumbers);
        } catch (ParseFailedException e) {
            ScriptException se = parseRubyParseException(e);

            // find start of error (column is normally the end)...
            int targetLine = se.getLineNumber() - 1;
            if (targetLine >= lineCount)
                targetLine = lineCount - 1; // For EOF errors
            int col = se.getColumnNumber();
            String l = lines[targetLine];
            char[] chars = l.toCharArray();
            int start = col;
            for (; start > 0; start--) {
                char c = chars[start];
                if (Character.isWhitespace(c)) {
                    start++;
                    break;
                }
            }
            int end = col;
            for (; end < chars.length; end++) {
                char c = chars[end];
                if (Character.isWhitespace(c))
                    break;
            }
            int len = end - start;
            dpr.setParsedLines(0, targetLine);
            int off = 0;
            for (int i = 0; i < targetLine; i++)
                off += lines[i].length() + 1;
            off += start;
            DefaultParserNotice not = new DefaultParserNotice(this, se.getLocalizedMessage(), targetLine, off, len);
            not.setShowInEditor(true);
            not.setLevel(DefaultParserNotice.ERROR);
            dpr.addNotice(not);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            gvars.set("$stderr", orig);
        }
        return dpr;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.