I've been looking at the Rhino [documentation](https://developer.mozilla.org/en-US/docs/Rhino/Embedding_tutorial#JavaScript_host_objects) and [source code](https://github.com/mozilla/rhino/blob/master/src/org/mozilla/javascript/NativeGlobal.java) 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.

After reading the [code](https://github.com/ringo/ringojs/blob/master/src/org/ringojs/engine/Require.java) of the implementation of the `require` function in RingoJS I believe I need to do something along the following lines:

```
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;
    }
}

```

Am I on the correct track? A step by step walkthrough on how to achieve this would be great.

Also it would be great if I could use Rhino's `defineClass` 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.