programming

magical interfacing c++ with another language : sep 02

have the other language generate your .hpp file. this lets you program directly in c++ and at the same time make it accessable to your scripting language and add introspection to c++ and still keep the language as c++ and not something else. the compiler will also catch all errors.

#ifndef gbGeom_hpp
#define gbGeom_hpp

#include"gb.hpp"

$class class gbGeom : public gbGroupNode
{

public:

$member float16 _modelMatrix;

public:

$constructor gbGeom();

public:

$method virtual void paint(gbGlyphContext* gc,gbGraphics* gr);

public:

$method virtual const gbClass* getClass();

};

const gbClass* gbGeom_getClass()
{
$generatedbody
}

#endif

so it is the same as the header file with extra meta information that is removed when it is generated and the generated code is placed in $generatedbody

$generateBody could look like:

static gbClass* clazz=null;
if(clazz!=null){return clazz;}
clazz=new gbClass("gbGeom");

clazz->begin(gbClass::BEGIN_INHERIT);
clazz->modifier(gbClass::MODIFIER_PUBLIC);
clazz->name("gbGroupNode");
clazz->end();

clazz->begin(gbClass::BEGIN_MEMBER_VARIABLE);
clazz->modifier(gbClass::MODIFIER_PUBLIC);
clazz->type("float16");
clazz->name("_modelMatrix");
clazz->memberVariable(new gbMemberVariable_float16(&gbGeom::_modelMatrix));
clazz->end();

clazz->begin(gbClass::BEGIN_CONSTRUCTOR);
clazz->modifier(gbClass::MODIFIER_PUBLIC);
clazz->constructor(new gbConstructor(&gbGeom::gbGeom()));
clazz->end();

clazz->begin(gbClass::BEGIN_METHOD);
clazz->modifier(gbClass::MODIFIER_PUBLIC);
clazz->modifier(gbClass::MODIFIER_VIRTUAL);
clazz->returnType("void");
clazz->name("paint");
clazz->argument("gbGlyphContext*");
clazz->argument("gbGraphics*");
clazz->method(new gbMethod(&gbGeom::paint(gbGlyphContext*,gbGraphics*));
clazz->end();

clazz=new gbClass("class gbGeom : public gbGroupNode");
clazz->public();
clazz->member("float16 _modelMatrix",new gbMemberVariable(&gbGeom::_modelMatrix));
clazz->public();

return clazz;
}

gbWire* wire=new gbWire(geom,"_angularVelocity");
wire->setValue(float3(0,0,0));