Skip to content

Instantly share code, notes, and snippets.

@rue
Forked from anonymous/gist:10246
Created September 11, 2008 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rue/10253 to your computer and use it in GitHub Desktop.
Save rue/10253 to your computer and use it in GitHub Desktop.
/**
* 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