I'm trying to eliminate a bunch of boilerplate code by using macros.
Here's what works. I can replace:
int do_register_script(struct context *L)
{
method_type const _instance_methods[] = {
{"new", __new},
{"delete", __delete}
{NULL, NULL}
};
register_type(L, script, _instance_methods, 0);
return 1;
}
with a macro
#define do_register_type(name) \
int do_register_ ## name(struct context *L) \
{ \
method_type const _instance_methods[] = { \
{"new", __new}, \
{"delete", __delete}, \
{NULL, NULL} \
}; \
register_type(L, name, _instance_methods, 0); \
return 1; \
}
like so:
do_register_type(script);
which is perfect!
But I also have some that look like this:
int do_register_rectangle(struct context *L)
{
method_type const _instance_methods[] = {
{"new", __new},
{"delete", __delete},
{"area", area},
{"perimeter", perimeter}
{NULL, NULL}
};
register_type(L, rectangle, _instance_methods, 0);
return 1;
}
And now the above macro doesn't work.
How can I add another parameter to the macro to support this?
I'm using C, not C++, so no templates.
UPDATE: Also sometimes the code this is going in uses aliases for the names
{"area", area},
{"Area", area},
{"perimeter", perimeter}
{"Perimeter", perimeter}