Created
October 6, 2009 16:36
-
-
Save josephruscio/203179 to your computer and use it in GitHub Desktop.
Macro-fu to export C constants into Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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