$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Warrick Buchanan (Warrick_at_[hidden])
Date: 2004-03-18 05:43:49
Hi,
As the subject says I'm trying to a boost::python like equivalent for
SpiderMonkey (Netscape's JavaScript engine) and I've been trying(!) to look
at boost::python for inspiration. I've got to the stage where I can quite
happily expose a class like so:
// D3D's Vector class just for example
Declare<D3DXVECTOR>::Property<0>("x", &D3DXVECTOR3::x); // 0 is 'tinyid'
Declare<D3DXVECTOR>::Property<1>("y", &D3DXVECTOR3::y); // 1 is 'tinyid'
Declare<D3DXVECTOR>::Property<2>("z", &D3DXVECTOR3::z); // 2 is 'tinyid'
Declare<D3DXVECTOR>::Definition("Vector3", jsContext, jsObject,
jsPrototype);
Just from those four lines you can then use the C++ class in JavaScript
without issue ie:
var v = new Vector3();
v.x = 4.0f;
...etc...
Now I want to expose methods and constructors. Originally I was planning to
have a load of templates for each number of arguments a function could
possibly take (which obviously isn't ideal), but looking at boost::python it
seems it has a more elegant but currently illegible to me way of doing this?
Has anyone got any pointers to how this works or comments that would help my
understanding?
Thanks,
Warrick