by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Richard Andrew Cattermole
    @rikkimax
    I want to get method calling done, before another PR
    James Mahler
    @jamesmahler
    ok
    let me know when it's ready and I'll get it in there and look what all you have on bindings
    JDBC bindings are on my list
    Richard Andrew Cattermole
    @rikkimax
    my bindings will be very minimal
    only enough to test
    James Mahler
    @jamesmahler
    yeah... but I'll see what I can reuse / etc to do it
    I've done JDBC from C and C++ before
    Richard Andrew Cattermole
    @rikkimax
    ahh righto
    James Mahler
    @jamesmahler
    I'd hope this go is easier... since we are making the jvm bindings
    I'll try to make the template that makes the stupid signatures (ex. "(I)C") also
    Richard Andrew Cattermole
    @rikkimax
    oh dammit, I haven't added the ability to create instances of a java object with only its identifier
    James Mahler
    @jamesmahler
    Richard Andrew Cattermole
    @rikkimax
    not to worry, I have those docs open
    oh and btw this is actually useful for me, my book has a section on this now
    James Mahler
    @jamesmahler
    It's the end of my day anyways... I gotta be up for work in 8 hours
    look forward to seeing the progress you make
    Richard Andrew Cattermole
    @rikkimax
    ok, night
    Richard Andrew Cattermole
    @rikkimax
    right todo list
    fields
    static methods and fields
    caching method and field ids
    and lastly a MyObjectType
    because of how mixin templates work you cannot refer to the type being created
    I also want another trick to be added, where by you can use string/String interchangeably during method calls
    which will require some switcheroo and meta programming in generated code
    Richard Andrew Cattermole
    @rikkimax
    class String : JRootObject {
            this(jobject id) {
                    DJvm djvm = DJvm.getInstance;
                    myJavaClassID_ = djvm.findClass("java.lang.String");
                    if (myJavaClassID_ is null) throw new NonCreatableClass("Cannot create a class, unknown class java.lang.String.");
                    myJavaObjectID_ = id;
            }
            private jobject myJavaObjectID_;
            private JClass myJavaClassID_;
            @property jobject myJavaObjectId() { return myJavaObjectID_; }
            @property JClass myJavaClassID() { return myJavaClassID_; }
            this(string a0) {
                    DJvm djvm = DJvm.getInstance;
                    myJavaClassID_ = djvm.findClass("java.lang.String");
                    if (myJavaClassID_ is null) throw new NonCreatableClass("Cannot create a class, unknown class java.lang.String.");
                    JNIEnv* env = djvm.env;
                    if (env is null) throw new NonCreatableClass("Cannot create a class, environement unknown.");
                    JMethod mid = myJavaClassID_.getMethod("<init>", "(Ljava/lang/String;)V");
                    if (myJavaClassID_ is null) throw new NonCreatableClass("Cannot create a class, unknown method constructor for arguments, (Ljava/lang/String;)V.");
                    myJavaObjectID_ = (*env).NewObject(env, myJavaClassID_.cls, mid.methodID, (*env).NewStringUTF(env, a0.toStringz));
            }
            this() {
                    DJvm djvm = DJvm.getInstance;
                    myJavaClassID_ = djvm.findClass("java.lang.String");
                    if (myJavaClassID_ is null) throw new NonCreatableClass("Cannot create a class, unknown class java.lang.String.");
                    JNIEnv* env = djvm.env;
                    if (env is null) throw new NonCreatableClass("Cannot create a class, environement unknown.");
                    JMethod mid = myJavaClassID_.getMethod("<init>", "()V");
                    if (myJavaClassID_ is null) throw new NonCreatableClass("Cannot create a class, unknown method constructor for arguments, ()V.");
                    myJavaObjectID_ = (*env).NewObject(env, myJavaClassID_.cls, mid.methodID, );
            }
            char charAt(int a0) {
                    JNIEnv* env = DJvm.getInstance.env;
                    jmethodID mid = (*env).GetMethodID(env, myJavaClassID_.cls, cast(const(char)*)"charAt".toStringz, cast(const(char)*)"(I)C".toStringz);
                    auto ret = (*env).CallByteMethod(env, myJavaObjectID_, mid, jvalue.fromValue(a0));
                    return cast(char)ret;
            }
            string concat(string a0) {
                    JNIEnv* env = DJvm.getInstance.env;
                    jmethodID mid = (*env).GetMethodID(env, myJavaClassID_.cls, cast(const(char)*)"concat".toStringz, cast(const(char)*)"(Ljava/lang/String;)Ljava/lang/String;".toStringz);
                    auto ret = (*env).CallObjectMethod(env, myJavaObjectID_, mid, (*env).NewStringUTF(env, a0.toStringz));
                    int len = (*env).GetStringUTFLength(env, ret);
                    auto retv = (*env).GetStringUTFChars(env, ret, null);
                    string retv2 = cast(string)retv[0 .. len].idup;
                    (*env).ReleaseStringUTFChars(env, ret, retv);
                    return retv2;
            }
            static @property string javaMangleOf() pure { return "java/lang/String"; }
    }
    currently generated text
    Richard Andrew Cattermole
    @rikkimax
    hmm
    James Mahler
    @jamesmahler
    How's the pull request coming... I've been trying to hold of going too crazy or far since I know it's coming.
    Richard Andrew Cattermole
    @rikkimax
    I haven't been working on it
    I have a book that I'm rewriting into markdown about ctfe, and once that is done will extremely close to publication
    and I'm working on a book series proposal
    James Mahler
    @jamesmahler
    OK... I'll continue on my path then... And we can figure out merging / etc later
    Richard Andrew Cattermole
    @rikkimax
    I'll have a check of what is in repo
    ok I now remember
    its currently just refactored out into better structure
    is worth a PR
    even if I pr, it won't end well
    it can't be auto merged because of the revert
    Richard Andrew Cattermole
    @rikkimax

    ```D
    class String : JRootObject {
    this(jobject id) {
    myJavaObjectID_ = id;
    }
    private jobject myJavaObjectID_;
    @property jobject myJavaObjectId() { return myJavaObjectID_; }
    static {
    private JClass myJavaClassID_;
    @property JClass myJavaClassId() {
    if (myJavaClassID is null) myJavaClassID = DJvm.getInstance.findClass("java.lang.String");
    return myJavaClassID_; }
    }

        this(string a0) {
                DJvm djvm = DJvm.getInstance;
                JNIEnv* env = djvm.env;
                if (env is null) throw new NonCreatableClass("Cannot create a class, environement unknown.");
                JMethod mid = myJavaClassId.getMethod("<init>", "(Ljava/lang/String;)V");
                if (myJavaClassId is null) throw new NonCreatableClass("Cannot create a class, unknown method constructor for arguments, (Ljava/lang/String;)V.");
                myJavaObjectID_ = (*env).NewObject(env, myJavaClassId.cls, mid.methodID, (*env).NewStringUTF(env, a0.toStringz));
        }
        this() {
                DJvm djvm = DJvm.getInstance;
                JNIEnv* env = djvm.env;
                if (env is null) throw new NonCreatableClass("Cannot create a class, environement unknown.");
                JMethod mid = myJavaClassId.getMethod("<init>", "()V");
                if (myJavaClassId is null) throw new NonCreatableClass("Cannot create a class, unknown method constructor for arguments, ()V.");
                myJavaObjectID_ = (*env).NewObject(env, myJavaClassId.cls, mid.methodID, );
        }
        char charAt(int a0) {
                JNIEnv* env = DJvm.getInstance.env;
                jmethodID mid = (*env).GetMethodID(env, myJavaClassId.cls, cast(const(char)*)"charAt".toStringz, cast(const(char)*)"(I)C".toStringz);
                auto ret = (*env).CallByteMethod(env, myJavaObjectId(), mid, jvalue.fromValue(a0));
                return cast(char)ret;
        }
        string concat(string a0) {
                JNIEnv* env = DJvm.getInstance.env;
                jmethodID mid = (*env).GetMethodID(env, myJavaClassId.cls, cast(const(char)*)"concat".toStringz, cast(const(char)*)"(Ljava/lang/String;)Ljava/lang/String;".toStringz);
                auto ret = (*env).CallObjectMethod(env, myJavaObjectId(), mid, (*env).NewStringUTF(env, a0.toStringz));
                int len = (*env).GetStringUTFLength(env, ret);
                auto retv = (*env).GetStringUTFChars(env, ret, null);
                string retv2 = cast(string)retv[0 .. len].idup;
                (*env).ReleaseStringUTFChars(env, ret, retv);
                return retv2;
        }
        static string valueOf(bool a0) {
                JNIEnv* env = DJvm.getInstance.env;
                jmethodID mid = (*env).GetMethodID(env, myJavaClassId.cls, cast(const(char)*)"valueOf".toStringz, cast(const(char)*)"(Z)Ljava/lang/String;".toStringz);
                auto ret = (*env).CallStaticObjectMethod(env, myJavaClassId().cls, mid, jvalue.fromValue(a0));
                int len = (*env).GetStringUTFLength(env, ret);
                auto retv = (*env).GetStringUTFChars(env, ret, null);
                string retv2 = cast(string)retv[0 .. len].idup;
                (*env).ReleaseStringUTFChars(env, ret, retv);
                return retv2;
        }
        @property bool myfield() {
                JNIEnv* env = DJvm.getInstance.env;
                JField field = myJavaClassId().getField("myfield", "Z");
                auto ret = (*env).GetBooleanField(env, myJavaObjectId(), field.fieldId);
                return cast(bool)ret;
        }
        @property void myfield(bool toset) {
                JNIEnv* env = DJvm.getInstance.env;
                JField field = myJavaClassId().getField("myfield", "Z");
                (*env).SetBooleanField(env, myJavaObjectId(), field.fieldId, toset);
        }
    
        static @property string javaMangleOf() pure { return "java/lang/String"; }

    }

    gitter.im isn't playing nicely with this text
    but it can now generate set/get fields
    oh and static methods and fields also should work
    I probably won't be handling caching of e.g. method id's
    at this point I'm gonna push to my fork
    it needs a lot of love in terms of refactoring
    a lot of the hard coding functionality I have could be pushed into your e.g. JClass
    and significantly improved them
    at this point however, its just refactoring that needs to happen, the logic is all there for Java from D