Dynamically expose C api to squirrel

88 Views Asked by At

I have this C function

bool gfx_draw_line(float x1, float y1, float x2, float y2, int r, int g, int b, int a)
{
   bool success = true;
   // draw line...
   return success;
}

I want to expose it to squirrel, but I have to manually create a SQFUNCTION as such

static SQInteger api_drawline(HSQUIRRELVM v)
{
        SQFloat   x1, y1, x2, y2; 
        SQInteger r, g, b, a;
        int       arg = 1;
        sq_getfloat(v, ++arg, &x1);
        sq_getfloat(v, ++arg, &y1);
        sq_getfloat(v, ++arg, &x2);
        sq_getfloat(v, ++arg, &y2);
        sq_getinteger(v, ++arg, &r);
        sq_getinteger(v, ++arg, &g);
        sq_getinteger(v, ++arg, &b);
        sq_getinteger(v, ++arg, &a);
        int s = gfx_draw_line(x1, y1, x2, y2, r, g, b, a);
        sq_pushbool(v, s);
        return 1;
}

Is there a way in C to dynamically generate the SQFUNCTION object? Say a macro or a function which would create the SQFUNCTION object from a function so that I can use it like that

SQFUNCTION sq = create_sqfunction(gfx_draw_line);
0

There are 0 best solutions below