So I was perusing the TurboSphere source, and I have to say, you make pretty creative use of preprocessor macros.
#define ENSURE_PROP(NAME, VALUATOR, WRAPPER)\
if(has_##NAME){\
JS::RootedValue out_value(ctx);\
JS_GetProperty(ctx, that, #NAME, &out_value);\
if(!VALUATOR){\
return false;\
}\
WRAPPER\
}
ENSURE_PROP(x, true, vertex.x = out_value.toNumber();)
ENSURE_PROP(y, true, vertex.y = out_value.toNumber();)
ENSURE_PROP(u, out_value.isNumber(), vertex.u = out_value.toNumber();)
ENSURE_PROP(v, out_value.isNumber(), vertex.v = out_value.toNumber();)
ENSURE_PROP(color, out_value.isObject() && color_proto.instanceOf(ctx, out_value, nullptr),
{TS_Color *color = color_proto.unsafeUnwrap(out_value.toObjectOrNull());
vertex.color = TS_Color(color->red, color->green, color->blue, color->alpha);}
)
#undef ENSURE_PROP
I think somebody misses their closures.