Skip to content

Instantly share code, notes, and snippets.

@josephruscio
Created October 6, 2009 16:36
Show Gist options
  • Save josephruscio/203179 to your computer and use it in GitHub Desktop.
Save josephruscio/203179 to your computer and use it in GitHub Desktop.
Macro-fu to export C constants into Ruby
/*
* Macro-fu to simplify the exporting C constants from a Ruby extension.
*/
#define EXPORT_RB_CONST(val, x) \
do{ rb_define_const(val, #x, INT2NUM(x)); } while(0)
#define BAR 42
void
Init_foo(void)
{
VALUE foo = rb_define_module("Foo");
/* Now you can replace this:
* rb_define_const(foo, "BAR", INT2NUM(BAR));
* with:
*/
EXPORT_RB_CONST(foo, BAR);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment