texplay 0.2.800 → 0.2.900

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/CHANGELOG +138 -119
  2. data/README.markdown +43 -41
  3. data/Rakefile +68 -68
  4. data/examples/common.rb +8 -8
  5. data/examples/example_alpha_blend.rb +31 -31
  6. data/examples/example_bezier.rb +42 -42
  7. data/examples/example_color_control.rb +69 -69
  8. data/examples/example_color_transform.rb +64 -67
  9. data/examples/example_color_transform_circle.rb +65 -0
  10. data/examples/example_dup.rb +75 -75
  11. data/examples/example_each.rb +42 -42
  12. data/examples/example_effect.rb +35 -35
  13. data/examples/example_fill.rb +44 -44
  14. data/examples/example_fill_old.rb +49 -49
  15. data/examples/example_fluent.rb +31 -31
  16. data/examples/example_gen_eval.rb +34 -34
  17. data/examples/example_hash_arguments.rb +47 -47
  18. data/examples/example_light.rb +77 -0
  19. data/examples/example_lsystem.rb +61 -61
  20. data/examples/example_melt.rb +27 -27
  21. data/examples/example_meyet.rb +64 -0
  22. data/examples/example_polyline.rb +43 -43
  23. data/examples/example_scale.rb +29 -29
  24. data/examples/example_simple.rb +48 -38
  25. data/examples/example_sync.rb +60 -60
  26. data/examples/example_trace.rb +1 -1
  27. data/examples/example_turtle.rb +40 -40
  28. data/examples/example_weird.rb +3 -1
  29. data/examples/media/Thumbs.db +0 -0
  30. data/ext/texplay/actions.c +999 -1001
  31. data/ext/texplay/actions.h +60 -60
  32. data/ext/texplay/bindings.c +1162 -1149
  33. data/ext/texplay/bindings.h +46 -46
  34. data/ext/texplay/cache.c +118 -118
  35. data/ext/texplay/cache.h +24 -24
  36. data/ext/texplay/compat.h +27 -27
  37. data/ext/texplay/extconf.rb +28 -28
  38. data/ext/texplay/gen_eval.c +211 -211
  39. data/ext/texplay/gen_eval.h +20 -20
  40. data/ext/texplay/graphics_utils.c +188 -63
  41. data/ext/texplay/graphics_utils.h +0 -1
  42. data/ext/texplay/object2module.c +171 -171
  43. data/ext/texplay/object2module.h +11 -11
  44. data/ext/texplay/texplay.c +169 -169
  45. data/ext/texplay/texplay.h +147 -130
  46. data/ext/texplay/utils.c +816 -752
  47. data/ext/texplay/utils.h +151 -145
  48. data/lib/texplay-contrib.rb +171 -171
  49. data/lib/texplay.rb +162 -137
  50. data/lib/texplay/version.rb +1 -1
  51. metadata +9 -5
@@ -1,211 +1,211 @@
1
- /* gen_eval.c */
2
- /* (C) John Mair 2009
3
- * This program is distributed under the terms of the MIT License
4
- * */
5
-
6
- #include <ruby.h>
7
- #include "object2module.h"
8
- #include "compat.h"
9
-
10
- VALUE
11
- retrieve_hidden_self(VALUE duped_context)
12
- {
13
- VALUE thread_id, unique_name, hidden_self;
14
-
15
- /* retrieve hidden self (if it exists) */
16
- thread_id = rb_funcall(rb_obj_id(rb_thread_current()), rb_intern("to_s"), 0);
17
- unique_name = rb_str_plus(rb_str_new2("__hidden_self__"), thread_id);
18
-
19
- hidden_self = rb_ivar_get(duped_context, rb_to_id(unique_name));
20
-
21
- return hidden_self;
22
- }
23
-
24
- void
25
- set_hidden_self(VALUE duped_context, VALUE hidden_self)
26
- {
27
- VALUE thread_id, unique_name;
28
-
29
- /* generate a unique (thread safe) name for the hidden self */
30
- thread_id = rb_funcall(rb_obj_id(rb_thread_current()), rb_intern("to_s"), 0);
31
- unique_name = rb_str_plus(rb_str_new2("__hidden_self__"), thread_id);
32
-
33
- /* store self in hidden var in duped context */
34
- rb_ivar_set(duped_context, rb_to_id(unique_name), hidden_self);
35
- }
36
-
37
- VALUE
38
- rb_capture(VALUE self) {
39
- VALUE hidden_self;
40
- VALUE result;
41
-
42
- rb_need_block();
43
-
44
- hidden_self = retrieve_hidden_self(self);
45
-
46
- /* 2 cases: (1) if rb_gen_eval is active then instance_eval wrt hidden_self
47
- (2) otherwise simply yield to the block
48
- */
49
- if(!NIL_P(hidden_self))
50
- result = rb_obj_instance_eval(0, 0, hidden_self);
51
- else
52
- result = rb_yield(Qnil);
53
-
54
- /* we want the return value of capture to be the return value of the block */
55
- return result;
56
- }
57
-
58
- /** ruby 1.9 funcs **/
59
- #ifdef RUBY_19
60
- void
61
- redirect_iv_for_object(VALUE obj, VALUE dest)
62
- {
63
- if(TYPE(obj) != T_OBJECT)
64
- rb_raise(rb_eArgError, "must provide a T_OBJECT");
65
-
66
- if (!(RBASIC(dest)->flags & ROBJECT_EMBED) && ROBJECT_IVPTR(dest)) {
67
- rb_raise(rb_eArgError, "im sorry gen_eval does not yet work with this type of ROBJECT");
68
- }
69
- if (RBASIC(obj)->flags & ROBJECT_EMBED) {
70
- rb_raise(rb_eArgError, "im sorry gen_eval does not yet work with ROBJECT_EMBED types");
71
- }
72
- else {
73
- ROBJECT(dest)->as.heap.ivptr = ROBJECT(obj)->as.heap.ivptr;
74
- ROBJECT(dest)->as.heap.numiv = ROBJECT(obj)->as.heap.numiv;
75
- ROBJECT(dest)->as.heap.iv_index_tbl = ROBJECT(obj)->as.heap.iv_index_tbl;
76
- RBASIC(dest)->flags &= ~ROBJECT_EMBED;
77
- }
78
- }
79
-
80
- void
81
- release_iv_for_object(VALUE obj)
82
- {
83
- if(TYPE(obj) != T_OBJECT)
84
- rb_raise(rb_eArgError, "must provide a T_OBJECT");
85
-
86
- ROBJECT(obj)->as.heap.ivptr = (void *) 0;
87
- ROBJECT(obj)->as.heap.numiv = 0;
88
- ROBJECT(obj)->as.heap.iv_index_tbl = (void *) 0;
89
- RBASIC(obj)->flags &= ~ROBJECT_EMBED;
90
- }
91
- #endif
92
- /** end of ruby 1.9 funcs **/
93
-
94
- VALUE
95
- rb_gen_eval(int argc, VALUE * argv, VALUE self) {
96
- VALUE duped_context;
97
- VALUE is_a_module;
98
- VALUE context;
99
- VALUE result;
100
-
101
- rb_need_block();
102
-
103
- context = rb_funcall(rb_block_proc(), rb_intern("__context__"), 0);
104
-
105
- /* using Class instead of Object (where possible) because Object's iv_tbl setup in 1.9 is weird */
106
- #ifdef RUBY_19
107
- if(TYPE(context) == T_OBJECT)
108
- duped_context = rb_funcall(rb_cObject, rb_intern("new"), 0);
109
- else
110
- duped_context = rb_funcall(rb_cClass, rb_intern("new"), 0);
111
-
112
- #else
113
-
114
- duped_context = rb_funcall(rb_cClass, rb_intern("new"), 0);
115
-
116
- #endif
117
-
118
-
119
- /* the duped_context shares the context's iv_tbl.
120
- 2 cases: (1) external iv_tbl, (2) local iv_tbl
121
-
122
- NOTE: we do not need to save original iv_tbl before replacing it, a brand new Class
123
- instance does not yet have an iv_tbl (the pointer is set to 0)
124
- */
125
- if(FL_TEST(context, FL_EXIVAR))
126
- RCLASS_IV_TBL(duped_context) = (struct st_table *) rb_generic_ivar_table(context);
127
- else {
128
- #ifdef RUBY_19
129
- if(TYPE(context) == T_OBJECT)
130
- redirect_iv_for_object(context, duped_context);
131
- else {
132
- RCLASS_IV_TBL(duped_context) = (struct st_table *) RCLASS_IV_TBL(context);
133
- }
134
- #else
135
- RCLASS_IV_TBL(duped_context) = (struct st_table *) RCLASS_IV_TBL(context);
136
- #endif
137
-
138
-
139
- }
140
-
141
- /* ensure singleton exists */
142
- rb_singleton_class(context);
143
-
144
- /* set up the class hierarchy for our dup_context */
145
- KLASS_OF(duped_context) = rb_singleton_class_clone(context);
146
-
147
- /* if no args then default to mixing in 'self' */
148
- if(argc == 0) {
149
- argc = 1;
150
- argv = &self;
151
- }
152
-
153
- /* mix the objects (or self) into the duped context */
154
- rb_gen_extend(argc, argv, duped_context);
155
-
156
- /* store self in hidden var in duped context */
157
- set_hidden_self(duped_context, self);
158
-
159
- is_a_module = rb_funcall(duped_context, rb_intern("is_a?"), 1, rb_cModule);
160
-
161
- /* eval block wrt duped_context */
162
- if(is_a_module == Qtrue)
163
- result = rb_mod_module_eval(0, 0, duped_context);
164
- else
165
- result = rb_obj_instance_eval(0, 0, duped_context);
166
-
167
- /* clean up goes below */
168
-
169
- /* release context's iv_tbl from duped_context. */
170
- #ifdef RUBY_19
171
- if(TYPE(duped_context) == T_OBJECT)
172
- release_iv_for_object(duped_context);
173
- else {
174
- RCLASS_IV_TBL(duped_context) = (struct st_table *) 0;
175
- }
176
- #else
177
- RCLASS_IV_TBL(duped_context) = (struct st_table *) 0;
178
- #endif
179
-
180
- /* delete hidden self */
181
- set_hidden_self(duped_context, Qnil);
182
-
183
- return result;
184
- }
185
-
186
- void
187
- Init_gen_eval() {
188
-
189
- rb_define_method(rb_cObject, "gen_eval", rb_gen_eval, -1);
190
- rb_define_method(rb_cObject, "capture", rb_capture, 0);
191
-
192
- rb_define_method(rb_cObject, "to_module", rb_to_module , 0);
193
- rb_define_method(rb_cObject, "reset_tbls", rb_reset_tbls , 0);
194
- rb_define_method(rb_cObject, "gen_extend", rb_gen_extend, -1);
195
- rb_define_method(rb_cModule, "gen_include", rb_gen_include, -1);
196
-
197
- /* below is much too hard to achieve in pure C */
198
- rb_eval_string("class Proc;"
199
- " def __context__;"
200
- " eval('self', self.binding);"
201
- " end;"
202
- "end;"
203
- );
204
-
205
- rb_define_alias(rb_cObject, "gen_eval_with", "gen_eval");
206
- }
207
-
208
-
209
-
210
-
211
-
1
+ /* gen_eval.c */
2
+ /* (C) John Mair 2009
3
+ * This program is distributed under the terms of the MIT License
4
+ * */
5
+
6
+ #include <ruby.h>
7
+ #include "object2module.h"
8
+ #include "compat.h"
9
+
10
+ VALUE
11
+ retrieve_hidden_self(VALUE duped_context)
12
+ {
13
+ VALUE thread_id, unique_name, hidden_self;
14
+
15
+ /* retrieve hidden self (if it exists) */
16
+ thread_id = rb_funcall(rb_obj_id(rb_thread_current()), rb_intern("to_s"), 0);
17
+ unique_name = rb_str_plus(rb_str_new2("__hidden_self__"), thread_id);
18
+
19
+ hidden_self = rb_ivar_get(duped_context, rb_to_id(unique_name));
20
+
21
+ return hidden_self;
22
+ }
23
+
24
+ void
25
+ set_hidden_self(VALUE duped_context, VALUE hidden_self)
26
+ {
27
+ VALUE thread_id, unique_name;
28
+
29
+ /* generate a unique (thread safe) name for the hidden self */
30
+ thread_id = rb_funcall(rb_obj_id(rb_thread_current()), rb_intern("to_s"), 0);
31
+ unique_name = rb_str_plus(rb_str_new2("__hidden_self__"), thread_id);
32
+
33
+ /* store self in hidden var in duped context */
34
+ rb_ivar_set(duped_context, rb_to_id(unique_name), hidden_self);
35
+ }
36
+
37
+ VALUE
38
+ rb_capture(VALUE self) {
39
+ VALUE hidden_self;
40
+ VALUE result;
41
+
42
+ rb_need_block();
43
+
44
+ hidden_self = retrieve_hidden_self(self);
45
+
46
+ /* 2 cases: (1) if rb_gen_eval is active then instance_eval wrt hidden_self
47
+ (2) otherwise simply yield to the block
48
+ */
49
+ if(!NIL_P(hidden_self))
50
+ result = rb_obj_instance_eval(0, 0, hidden_self);
51
+ else
52
+ result = rb_yield(Qnil);
53
+
54
+ /* we want the return value of capture to be the return value of the block */
55
+ return result;
56
+ }
57
+
58
+ /** ruby 1.9 funcs **/
59
+ #ifdef RUBY_19
60
+ void
61
+ redirect_iv_for_object(VALUE obj, VALUE dest)
62
+ {
63
+ if(TYPE(obj) != T_OBJECT)
64
+ rb_raise(rb_eArgError, "must provide a T_OBJECT");
65
+
66
+ if (!(RBASIC(dest)->flags & ROBJECT_EMBED) && ROBJECT_IVPTR(dest)) {
67
+ rb_raise(rb_eArgError, "im sorry gen_eval does not yet work with this type of ROBJECT");
68
+ }
69
+ if (RBASIC(obj)->flags & ROBJECT_EMBED) {
70
+ rb_raise(rb_eArgError, "im sorry gen_eval does not yet work with ROBJECT_EMBED types");
71
+ }
72
+ else {
73
+ ROBJECT(dest)->as.heap.ivptr = ROBJECT(obj)->as.heap.ivptr;
74
+ ROBJECT(dest)->as.heap.numiv = ROBJECT(obj)->as.heap.numiv;
75
+ ROBJECT(dest)->as.heap.iv_index_tbl = ROBJECT(obj)->as.heap.iv_index_tbl;
76
+ RBASIC(dest)->flags &= ~ROBJECT_EMBED;
77
+ }
78
+ }
79
+
80
+ void
81
+ release_iv_for_object(VALUE obj)
82
+ {
83
+ if(TYPE(obj) != T_OBJECT)
84
+ rb_raise(rb_eArgError, "must provide a T_OBJECT");
85
+
86
+ ROBJECT(obj)->as.heap.ivptr = (void *) 0;
87
+ ROBJECT(obj)->as.heap.numiv = 0;
88
+ ROBJECT(obj)->as.heap.iv_index_tbl = (void *) 0;
89
+ RBASIC(obj)->flags &= ~ROBJECT_EMBED;
90
+ }
91
+ #endif
92
+ /** end of ruby 1.9 funcs **/
93
+
94
+ VALUE
95
+ rb_gen_eval(int argc, VALUE * argv, VALUE self) {
96
+ VALUE duped_context;
97
+ VALUE is_a_module;
98
+ VALUE context;
99
+ VALUE result;
100
+
101
+ rb_need_block();
102
+
103
+ context = rb_funcall(rb_block_proc(), rb_intern("__context__"), 0);
104
+
105
+ /* using Class instead of Object (where possible) because Object's iv_tbl setup in 1.9 is weird */
106
+ #ifdef RUBY_19
107
+ if(TYPE(context) == T_OBJECT)
108
+ duped_context = rb_funcall(rb_cObject, rb_intern("new"), 0);
109
+ else
110
+ duped_context = rb_funcall(rb_cClass, rb_intern("new"), 0);
111
+
112
+ #else
113
+
114
+ duped_context = rb_funcall(rb_cClass, rb_intern("new"), 0);
115
+
116
+ #endif
117
+
118
+
119
+ /* the duped_context shares the context's iv_tbl.
120
+ 2 cases: (1) external iv_tbl, (2) local iv_tbl
121
+
122
+ NOTE: we do not need to save original iv_tbl before replacing it, a brand new Class
123
+ instance does not yet have an iv_tbl (the pointer is set to 0)
124
+ */
125
+ if(FL_TEST(context, FL_EXIVAR))
126
+ RCLASS_IV_TBL(duped_context) = (struct st_table *) rb_generic_ivar_table(context);
127
+ else {
128
+ #ifdef RUBY_19
129
+ if(TYPE(context) == T_OBJECT)
130
+ redirect_iv_for_object(context, duped_context);
131
+ else {
132
+ RCLASS_IV_TBL(duped_context) = (struct st_table *) RCLASS_IV_TBL(context);
133
+ }
134
+ #else
135
+ RCLASS_IV_TBL(duped_context) = (struct st_table *) RCLASS_IV_TBL(context);
136
+ #endif
137
+
138
+
139
+ }
140
+
141
+ /* ensure singleton exists */
142
+ rb_singleton_class(context);
143
+
144
+ /* set up the class hierarchy for our dup_context */
145
+ KLASS_OF(duped_context) = rb_singleton_class_clone(context);
146
+
147
+ /* if no args then default to mixing in 'self' */
148
+ if(argc == 0) {
149
+ argc = 1;
150
+ argv = &self;
151
+ }
152
+
153
+ /* mix the objects (or self) into the duped context */
154
+ rb_gen_extend(argc, argv, duped_context);
155
+
156
+ /* store self in hidden var in duped context */
157
+ set_hidden_self(duped_context, self);
158
+
159
+ is_a_module = rb_funcall(duped_context, rb_intern("is_a?"), 1, rb_cModule);
160
+
161
+ /* eval block wrt duped_context */
162
+ if(is_a_module == Qtrue)
163
+ result = rb_mod_module_eval(0, 0, duped_context);
164
+ else
165
+ result = rb_obj_instance_eval(0, 0, duped_context);
166
+
167
+ /* clean up goes below */
168
+
169
+ /* release context's iv_tbl from duped_context. */
170
+ #ifdef RUBY_19
171
+ if(TYPE(duped_context) == T_OBJECT)
172
+ release_iv_for_object(duped_context);
173
+ else {
174
+ RCLASS_IV_TBL(duped_context) = (struct st_table *) 0;
175
+ }
176
+ #else
177
+ RCLASS_IV_TBL(duped_context) = (struct st_table *) 0;
178
+ #endif
179
+
180
+ /* delete hidden self */
181
+ set_hidden_self(duped_context, Qnil);
182
+
183
+ return result;
184
+ }
185
+
186
+ void
187
+ Init_gen_eval() {
188
+
189
+ rb_define_method(rb_cObject, "gen_eval", rb_gen_eval, -1);
190
+ rb_define_method(rb_cObject, "capture", rb_capture, 0);
191
+
192
+ rb_define_method(rb_cObject, "to_module", rb_to_module , 0);
193
+ rb_define_method(rb_cObject, "reset_tbls", rb_reset_tbls , 0);
194
+ rb_define_method(rb_cObject, "gen_extend", rb_gen_extend, -1);
195
+ rb_define_method(rb_cModule, "gen_include", rb_gen_include, -1);
196
+
197
+ /* below is much too hard to achieve in pure C */
198
+ rb_eval_string("class Proc;"
199
+ " def __context__;"
200
+ " eval('self', self.binding);"
201
+ " end;"
202
+ "end;"
203
+ );
204
+
205
+ rb_define_alias(rb_cObject, "gen_eval_with", "gen_eval");
206
+ }
207
+
208
+
209
+
210
+
211
+
@@ -1,20 +1,20 @@
1
- /* gen_eval.h */
2
-
3
- #ifndef GUARD_GEN_EVAL_H
4
- #define GUARD_GEN_EVAL_H
5
-
6
- #include <ruby.h>
7
-
8
- VALUE rb_gen_eval(int argc, VALUE * argv, VALUE self);
9
- VALUE rb_capture(VALUE self);
10
- VALUE retrieve_hidden_self(VALUE duped_context);
11
- void set_hidden_self(VALUE duped_context, VALUE hidden_self);
12
-
13
- /* change self to hidden self if __hidden_self__ defined */
14
- #define ADJUST_SELF(X) \
15
- do { \
16
- if(!NIL_P(retrieve_hidden_self((X)))) \
17
- (X) = retrieve_hidden_self((X)); \
18
- } while(0)
19
-
20
- #endif
1
+ /* gen_eval.h */
2
+
3
+ #ifndef GUARD_GEN_EVAL_H
4
+ #define GUARD_GEN_EVAL_H
5
+
6
+ #include <ruby.h>
7
+
8
+ VALUE rb_gen_eval(int argc, VALUE * argv, VALUE self);
9
+ VALUE rb_capture(VALUE self);
10
+ VALUE retrieve_hidden_self(VALUE duped_context);
11
+ void set_hidden_self(VALUE duped_context, VALUE hidden_self);
12
+
13
+ /* change self to hidden self if __hidden_self__ defined */
14
+ #define ADJUST_SELF(X) \
15
+ do { \
16
+ if(!NIL_P(retrieve_hidden_self((X)))) \
17
+ (X) = retrieve_hidden_self((X)); \
18
+ } while(0)
19
+
20
+ #endif