-
-
Save rue/10253 to your computer and use it in GitHub Desktop.
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
/** | |
* Create a writer method. | |
* | |
* For attr_writer(foo, SomeClass), creates void foo(STATE, SomeClass* obj) | |
* that sets the instance variable my_foo to the object given and runs the write | |
* barrier. | |
*/ | |
#define attr_writer(name, type) void name(STATE, type* obj) { \ | |
my_ ## name = obj; \ | |
state->om->write_barrier(this, obj); \ | |
} | |
/** | |
* Create a reader method. | |
* | |
* For attr_reader(foo, SomeClass), creates SomeClass* foo() which returns the | |
* instance variable my_foo. | |
*/ | |
#define attr_reader(name, type) type* name() { return my_ ## name; } | |
/** | |
* Ruby-like accessor creation. | |
* | |
* Both attr_writer and attr_reader. | |
*/ | |
#define attr_accessor(name, type) attr_reader(name, type) \ | |
attr_writer(name, type) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment