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!
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}];
?
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