#3 refining of object macros
authorxchaos <xchaos@4bb87942-c103-4e5a-b51c-0ebff58f8515>
Mon, 18 Aug 2008 10:14:08 +0000 (10:14 +0000)
committerxchaos <xchaos@4bb87942-c103-4e5a-b51c-0ebff58f8515>
Mon, 18 Aug 2008 10:14:08 +0000 (10:14 +0000)
git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@80 4bb87942-c103-4e5a-b51c-0ebff58f8515

cll1.h
demos/objects/objects-sample.c

diff --git a/cll1.h b/cll1.h
index d38f2cd5c11f4cadd323522a94340707dbf0bd5b..0ad5db9e0d0d67a0f2ddb15ffa42327051956708 100644 (file)
--- a/cll1.h
+++ b/cll1.h
@@ -85,6 +85,7 @@ extern  unsigned RANDOM_SEED;
 #define or ||
 #define TRUE 1
 #define FALSE 0
+#define PI 3.141592654
 #define WEIRDINT (1<<(sizeof(int)*8-1))
 #define btoa(EXPR) ((EXPR)?"TRUE":"FALSE")
 #define coalesce(VAR,EXPR) (VAR?VAR:(EXPR))
@@ -192,7 +193,7 @@ extern  unsigned RANDOM_SEED;
 /* variable declarators */
 #define Get_obj(ID,MEM,...) MEM ID=get_obj(MEM,__VA_ARGS__)
 #define Get_obj_as(ID,COMMUNITY,MEM,...) MEM ID=get_obj_as(COMMUNITY,MEM,INTERFACE,__VA_ARGS__)
-#define I_am(MEM) MEM self=(MEM)community
+#define I_am(SELF,MEM) MEM SELF=(MEM)community
 /* .----------------------------------------------------------------------.
   /  9. implementation of C<<1 library functions, updated 2008-01-26 xCh.
  '----------------------------------------------------------------------- */
index f0a800ae3d89352a1424f835f20a7288c236bd95..5b005636bdd2b04ffe6c0b8ca6fd8f28091fed39 100644 (file)
@@ -56,7 +56,7 @@ def_mem(Object_list)
 
 void drawTri(Shape community)
 {
- I_am(Tri);
+ I_am(self, Tri);
  
  printf("Drawing %s: %d,%d - %d,%d - %d,%d .\n",
         self->name, self->x1, self->y1, self->x2, self->y2, self->x3, self->y3);
@@ -64,7 +64,7 @@ void drawTri(Shape community)
 
 void drawRect(Shape community)
 {
- I_am(Rect);
+ I_am(self, Rect);
  
  printf("Drawing %s: %d,%d - %d,%d .\n",
         self->desc, self->x1, self->y1, self->x2, self->y2);
@@ -72,7 +72,7 @@ void drawRect(Shape community)
 
 void drawCirc(Shape community)
 {
- I_am(Circ);
+ I_am(self, Circ);
  
  printf("Drawing %s: %d,%d - r=%d .\n",
         self->comment, self->x1, self->y1, self->r);
@@ -80,7 +80,7 @@ void drawCirc(Shape community)
 
 void moveTri(Shape community, int x, int y)
 {
- I_am(Tri);
+ I_am(self, Tri);
  
  self->x1 += x;
  self->y1 += y;
@@ -92,7 +92,7 @@ void moveTri(Shape community, int x, int y)
 
 void moveRect(Shape community, int x, int y)
 {
- I_am(Rect);
+ I_am(self, Rect);
  
  self->x1 += x;
  self->y1 += y;
@@ -102,7 +102,7 @@ void moveRect(Shape community, int x, int y)
 
 void moveCirc(Shape community, int x, int y)
 {
- I_am(Circ);
+ I_am(self, Circ);
  
  self->x1 += x;
  self->y1 += y;
@@ -110,49 +110,49 @@ void moveCirc(Shape community, int x, int y)
 
 str descTri(Shape community)
 {
- I_am(Tri);
+ I_am(self, Tri);
  
  return self->name;
 }
 
 str descRect(Shape community)
 {
- I_am(Rect);
+ I_am(self, Rect);
 
  return self->desc;
 }
 
 str descCirc(Shape community)
 {
- I_am(Circ);
+ I_am(self, Circ);
  
  return self->comment;
 }
 
 float calcAreaTri(Shape community)
 {
- I_am(Tri);
+ I_am(self, Tri);
 
  return 0;
 }
 
 float calcAreaRect(Shape community)
 {
- I_am(Rect);
+ I_am(self, Rect);
 
- return (self->x2-self->x1)*(self->y2-self->y1);
+ return (self->x2 - self->x1)*(self->y2 - self->y1);
 }
 
 float calcAreaCirc(Shape community)
 {
- I_am(Circ);
+ I_am(self, Circ);
 
- return 3.14159*self->r*self->r;
+ return PI * self->r * self->r;
 }
 
 void setTri(Shape community, int x1, int y1, int x2, int y2, int x3, int y3)
 {
- I_am(Tri);
+ I_am(self, Tri);
 
  self->x1 = x1;
  self->y1 = y1;
@@ -164,7 +164,7 @@ void setTri(Shape community, int x1, int y1, int x2, int y2, int x3, int y3)
 
 void setRect(Shape community, int x1, int y1, int x2, int y2, int dummy1, int dummy2)
 {
- I_am(Rect);
+ I_am(self, Rect);
  
  self->x1 = x1;
  self->y1 = y1;
@@ -174,7 +174,7 @@ void setRect(Shape community, int x1, int y1, int x2, int y2, int dummy1, int du
 
 void setCirc(Shape community, int x1, int y1, int r, int dummy1, int dummy2, int dummy3)
 {
- I_am(Circ);
+ I_am(self, Circ);
  
  self->x1 = x1;
  self->y1 = y1;
@@ -183,7 +183,7 @@ void setCirc(Shape community, int x1, int y1, int r, int dummy1, int dummy2, int
 
 void nameRect(Shape community, str name)
 {
- I_am(Rect);
+ I_am(self, Rect);
  
  self->desc = name;
 }
This page took 0.245028 seconds and 4 git commands to generate.