I've decided to make minisphere's API functions more JS engine agnostic. They are now defined like this:
static js_retval_t
js_CreateColor(_JS_C_FUNC_ARGS_)
{
js_begin_api_func("CreateColor");
js_require_num_args(3);
js_int_arg(1, r_val);
js_int_arg(2, g_val);
js_int_arg(3, b_val);
js_maybe_int_arg(4, a_val, 255);
r_val = fmin(fmax(r_val, 0), 255);
g_val = fmin(fmax(g_val, 0), 255);
b_val = fmin(fmax(b_val, 0), 255);
a_val = fmin(fmax(a_val, 0), 255);
js_return_sphereobj(color, al_map_rgba(r_val, g_val, b_val, a_val));
}
Unlike Sphere's beginfunc() macro, this still looks like a normal C function and so doesn't hurt the code's readability.
The thing is though, I don't know if I'm up for the massive refactoring that's going to be required to get all my API functions to conform to this setup...