• This code is a simpler layout of the above by reference. It could be there is an error in the wrapper stuff in cFloat object.

    This mb works? Not sure yet.

    var c = E.compiledC(`
    // void fadd_byref(int,int,int)
    
    typedef union {
        float f;
        int i;
    } floatint;
    
    void fadd_byref(floatint* arg1, floatint* arg2, floatint* arg3)
    {
      floatint farg1,farg2;
      farg1.i=arg1->i;
      farg2.i=arg2->i;
    
      floatint out;
      out.f = farg1.f + farg2.f;
    
      arg3->i = out.i;
    }
    
    `);
    
    let f = new Float32Array(1);
    let r = E.getAddressOf(f,true);
    print(`a : ${r}`);
    f[0] = 0.3;
    
    let f1 = new Float32Array(1);
    let r1 = E.getAddressOf(f1,true);
    print(`a : ${r1}`);
    f1[0] = 0.63;
    
    let f2 = new Float32Array(1);
    let r2 = E.getAddressOf(f2,true);
    print(`a : ${r2}`);
    
    c.fadd_byref(r,r1,r2);
    print(f[0]);
    print(f1[0]);
    print(f2[0]);
    

    Edit: Yes this works, there is something wrong with the cFloat wrapper function I created. Yet I dont know what it is. So good news for the float ref working I guess.

    Make sure to use this:

    let fs = E.toFlatString(new Float32Array(1).buffer);
    if ( !fs ) throw new Error("Required to be a flatstring");
    let f = new Float32Array(E.toArrayBuffer(fs));
    
About

Avatar for d3nd3-o0 @d3nd3-o0 started