@SuppressWarnings({"PMD.NPathComplexity", "PMD.ExcessiveMethodLength"})
    private int stringByte(LuaCallFrame callFrame, int nArguments) {
        BaseLib.luaAssert(nArguments >= 1, "not enough arguments");
        String s = getStringArg(callFrame, 1, names[BYTE]);

        Double di = null;
        Double dj = null;
        if (nArguments >= 2) {
            di = getDoubleArg(callFrame, 2, names[BYTE]);
            if (nArguments >= 3) {
                dj = getDoubleArg(callFrame, 3, names[BYTE]);
            }
        }
        double di2 = 1;
        if (di != null) {
            di2 = LuaState.fromDouble(di);
        }
        double dj2 = di2;
        if (dj != null) {
            dj2 = LuaState.fromDouble(dj);
        }

        int ii = (int) di2;
        int ij = (int) dj2;

        int len = s.length();
        if (ii < 0) {
            ii += len + 1;
        }
        if (ii <= 0) {
            ii = 1;
        }
        if (ij < 0) {
            ij += len + 1;
        } else if (ij > len) {
            ij = len;
        }
        int nReturns = 1 +ij - ii;

        if (nReturns <= 0) {
            return 0;
        }
        callFrame.setTop(nReturns);
        int offset = ii - 1;
        for (int i = 0; i < nReturns; i++) {
            char c = s.charAt(offset + i);
            callFrame.set(i, new Double((double) c));
        }
        return nReturns;
    }
Only works with non-negative numbers
main/src/main/java/cgeo/geocaching/wherigo/kahlua/stdlib/StringLib.java