JS-CTYPES Status

Unfortunately, the js-ctypes project got back-burnered for a while. Fortunately, some great contributors swooped in and landed some really nice bits. Fredrik Larsson helped out on some Linux problems (bug 416119), filled in ANSI string support (bug 416229) and setup an xpcshell test framework (bug 427286).

The Atul Varma came to my rescue by adding support for OS X and fixing a small bug (bug 429063). Atul also added build instructions to the wiki. Brahmana found a bug too and posted a patch (bug 413783).

We are getting pretty close to a usable library. The next step is struct support. The current plan is to do something like this:


// define the struct
var POINT = [{"x": INT32}, {"y": INT32}];

// use the struct when declaring the function call
var pointsEqual = library.declare("PointsEqual", STDCALL, BOOLEAN, POINT, POINT);

// initialize objects that looks like POINT
var pt1 = {"x": 10, "y": 20};
var pt2 = {"x": 20, "y": 20};
var result = pointsEqual(pt1, pt2);

// "result" should be false :)

The wiki page has bugzilla and SVN information too. Feedback welcome. Patches welcome!

4 Comments

  1. sky said,

    April 17, 2008 @ 8:29 am

    From the example I’m confused, should the first line be:
    var POINT = {“x”: INT32, “y”: INT32};
    XOR the pt1 line be like:
    var pt1 = [{"x": 10}, {"y": 20}];
    ?

  2. Mark Finkle said,

    April 17, 2008 @ 1:42 pm

    sky – well, I was originally thinking it would work that way, but just like in Python, JavaScript object properties are stored in a hash and when iterating over the properties, order is not guaranteed (in SpiderMonkey). So, we use an array, just like Python ctypes, to define the struct.

    However, when actually using an object (pt1 for example) it is more “normal” for a JavaScript developer to use an object, not an array. Since the struct is defined in an indexed manner (using array), we can allow the use of objects for passing data.

    We could merge the concepts of defining the struct and using the struct as well.

    
    function POINT(x, y) {
      this.x = x; this.y = y;
    }
    
    POINT.prototype = {
      _fields_ : [{"x": INT32}, {"y": INT32}]
    }
    
    // _fields_ will be used internally to get the primitives
    var pointsEqual = library.declare("PointsEqual", STDCALL, BOOLEAN, POINT, POINT);
    
    var pt1 = new POINT(10, 20);
    var pt2 = new POINT(20, 20);
    var result = pointsEqual(pt1, pt2);
    

    Then the POINT object could be used for both defining and using POINTs

  3. Christopher Blizzard » Blog Archive » mozilla embedding overview & meetup notes said,

    April 29, 2008 @ 11:45 am

    [...] embedding apps that want to interact with the web in a different way or Dashboard-style widgets. (JS-ctypes, [...]

  4. Bridging the gap between native functions and Active Scripting with a COM-based FFI wrapper « KK’s Blog said,

    May 9, 2008 @ 2:18 pm

    [...] in April I stumbled upon this post in Planet Mozilla. It discussed recent improvements to JSctypes. It was the first time I had heard [...]

RSS feed for comments on this post