Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define $(x,y, args...) x->y(x, ## args)
- #define new(x, args...) new ## x (args)
- #define class(x) #define __CLASS__ x
- #define method(returns, name, args...) \
- #define __METHODS__ __METHODS__ ## returns (* name )( __CLASS__ *, ## args ); \
- returns name ( args )
- #define instance_var(arg) #define __METHODS__ ## arg ;
- #define end() \
- typedef struct {\
- __METHODS__\
- } __CLASS__;\
- #undef __CLASS__ \
- #undef __METHODS__
- class(Foo)
- method(void, foo, char *text)
- {
- printf("%s%c\n", text, self->ending);
- }
- instance_variable(ending);
- end()
- Foo *newFoo()
- {
- Foo *foo = (Foo*)malloc(sizeof(Foo));
- return foo;
- }
- int main()
- {
- Foo *foo = new(Foo);
- foo->ending = '!';
- $(foo, foo);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement