Hello, I've got a program written in C, and I'm trying to modify it so that people who aren't experienced with programming can modify the program. The idea was to create a sort of scripting language using macros, so that something like
BEGIN_FUNCTION( func1 )
set xpos to 0
add 5 to ypos
END_FUNCTION
would turn into something like
void func1(Object* o)
{
o->xpos = 0;
o->ypos += 5;
}
So then I started trying to create the macros... it was a little hackey, but I came up with the following:
#define to ,
#define BEGIN_FUNCTION(name) void name(Object* o) { do{}while(0
#define set ); set2(
#define add ); add2(
#define END_FUNCTION ); }
Which after being run through the preprocessor creates something like
void func1(Object* o)
{
do{} while(0);
set2(xpos, 0);
add2(5, ypos);
}
Ok, looks good. All that's left to do is create the set2 and add2 macros, right?
#define set2(var, val) o->var = val
#define add2(val, var) o->var += val
Wrong! The compiler gives "unterminated argument list invoking macro "set2"".
If I just paste the code in from the preprocessor output before defining set2 and add2, and then define them, it works just fine. Or by making set2 and add2 functions. Or by changing the script syntax so the user just types something like set(xpos, 0). I'm just curious to know, why the hell doesn't this work?