title: How are native functions created in Rhino?
body: <p>I've been looking at the Rhino <a href="https://developer.mozilla.org/en-US/docs/Rhino/Embedding_tutorial#JavaScript_host_objects" rel="nofollow">documentation</a> and <a href="https://github.com/mozilla/rhino/blob/master/src/org/mozilla/javascript/NativeGlobal.java" rel="nofollow">source code</a> for a clue as to how to implement my own global native function. This task is however more complicated than I expected it to be.</p>
  
  <p>After reading the <a href="https://github.com/ringo/ringojs/blob/master/src/org/ringojs/engine/Require.java" rel="nofollow">code</a> of the implementation of the <code>require</code> function in RingoJS I believe I need to do something along the following lines:</p>
  
  <pre><code>import org.mozilla.javascript.BaseFunction;
  import org.mozilla.javascript.Scriptable;
  import org.mozilla.javascript.Context;
  
  public class MyGlobalNativeFunction extends BaseFunction {
      public MyGlobalNativeFunction() {}
  
      public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
          // implementation of my function
      }
  
      public int getArity() {
          return 1;
      }
  }
  </code></pre>
  
  <p>Am I on the correct track? A step by step walkthrough on how to achieve this would be great.</p>
  
  <p>Also it would be great if I could use Rhino's <code>defineClass</code> function to create my global native function. I'm not too keen on rolling out my own modified version of Rhino just because I want to implement one native function.</p>