Advertisement
Guest User

Untitled

a guest
Oct 20th, 2012
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define $(x,y, args...) x->y(x, ## args)
  2. #define new(x, args...) new ## x (args)
  3. #define class(x) #define __CLASS__ x
  4. #define method(returns, name, args...) \
  5. #define __METHODS__ __METHODS__ ## returns (* name )( __CLASS__ *, ## args ); \
  6. returns name ( args )
  7. #define instance_var(arg) #define __METHODS__ ## arg ;
  8. #define end() \
  9.         typedef struct {\
  10.                 __METHODS__\
  11.         } __CLASS__;\
  12. #undef __CLASS__ \
  13. #undef __METHODS__
  14.  
  15. class(Foo)
  16.         method(void, foo, char *text)
  17.         {
  18.                 printf("%s%c\n", text, self->ending);
  19.         }
  20.         instance_variable(ending);
  21. end()
  22.  
  23. Foo *newFoo()
  24. {
  25.         Foo *foo = (Foo*)malloc(sizeof(Foo));
  26.         return foo;
  27. }
  28.  
  29. int main()
  30. {
  31.         Foo *foo = new(Foo);
  32.         foo->ending = '!';
  33.         $(foo, foo);
  34.         return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement