Package org.jruby.internal.runtime

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


     * @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

     * @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

     * @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

  private class Variables extends GlobalVariables {
    private Variables(Ruby runtime) {
      super(runtime);

      //we have to copy variables from the origin one to this
      GlobalVariables vars = runtime.getGlobalVariables();
      for (Iterator it = vars.getNames().iterator(); it.hasNext();) {
        final String nm = (String)it.next();
        set(nm, vars.get(nm));
      }
    }
View Full Code Here

        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

        }
    }

    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

        }
    }

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

        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 (Exception exp) {
            throw new ScriptException(exp);
View Full Code Here

        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

TOP

Related Classes of org.jruby.internal.runtime.GlobalVariables

Copyright © 2018 www.massapicom. 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.