reflexion 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,150 @@
1
+ #include "reflex/ruby/application.h"
2
+
3
+
4
+ #include <rucy.h>
5
+ #include "defs.h"
6
+
7
+
8
+ using namespace Rucy;
9
+
10
+
11
+ namespace Reflex
12
+ {
13
+
14
+
15
+ static Class cApplication;
16
+
17
+ Class
18
+ application_class ()
19
+ {
20
+ return cApplication;
21
+ }
22
+
23
+
24
+ }// Reflex
25
+
26
+
27
+ namespace Rucy
28
+ {
29
+
30
+
31
+ Value
32
+ value (const Reflex::Application& application)
33
+ {
34
+ return new_type<Reflex::Application>(
35
+ Reflex::application_class(), new Reflex::Application(application));
36
+ }
37
+
38
+
39
+ }// Rucy
40
+
41
+
42
+ class RubyApplication : public Reflex::Application
43
+ {
44
+
45
+ public:
46
+
47
+ typedef Reflex::Application Super;
48
+
49
+ Value self;
50
+
51
+ void mark ()
52
+ {
53
+ self.mark();
54
+ }
55
+
56
+ virtual bool run ()
57
+ {
58
+ SYM(run);
59
+ return self.call(run);
60
+ }
61
+
62
+ virtual bool quit ()
63
+ {
64
+ SYM(quit);
65
+ return self.call(quit);
66
+ }
67
+
68
+ virtual bool about ()
69
+ {
70
+ SYM(about);
71
+ return self.call(about);
72
+ }
73
+
74
+ };// RubyApplication
75
+
76
+
77
+ #define this ((RubyApplication*) to<Reflex::Application*>(self))
78
+
79
+ #define CHECK CHECK_OBJECT(self, RubyApplication, Reflex::application_class())
80
+
81
+
82
+ static
83
+ VALUE alloc(VALUE klass)
84
+ {
85
+ RubyApplication* app = new RubyApplication;
86
+ return app->self = new_type<RubyApplication>(klass, app, mark_type<RubyApplication>);
87
+ }
88
+
89
+ static
90
+ VALUE run(VALUE self)
91
+ {
92
+ CHECK;
93
+ if (!this->Super::run())
94
+ system_error("failed to run application.");
95
+ return self;
96
+ }
97
+
98
+ static
99
+ VALUE quit(VALUE self)
100
+ {
101
+ CHECK;
102
+ if (!this->Super::quit())
103
+ system_error("failed to quit application.");
104
+ return self;
105
+ }
106
+
107
+ static
108
+ VALUE about(VALUE self)
109
+ {
110
+ CHECK;
111
+ if (!this->Super::about())
112
+ system_error("failed to show about application.");
113
+ return self;
114
+ }
115
+
116
+ static
117
+ VALUE get_name(VALUE self)
118
+ {
119
+ CHECK;
120
+ String s;
121
+ if (!this->get_name(&s))
122
+ system_error("failed to get name of application.");
123
+ return Value(s.c_str());
124
+ }
125
+
126
+ static
127
+ VALUE set_name(VALUE self, VALUE name)
128
+ {
129
+ CHECK;
130
+ if (!this->set_name(name.c_str()))
131
+ system_error("failed to set name of application.");
132
+ return name;
133
+ }
134
+
135
+
136
+ void
137
+ Init_application ()
138
+ {
139
+ Module m = rb_define_module("Reflex");
140
+
141
+ Class c = rb_define_class_under(m, "Application", rb_cObject);
142
+ Reflex::cApplication = c;
143
+
144
+ rb_define_alloc_func(c, alloc);
145
+ rb_define_method(c, "run", RUBY_METHOD_FUNC(run), 0);
146
+ rb_define_method(c, "quit", RUBY_METHOD_FUNC(quit), 0);
147
+ rb_define_method(c, "about", RUBY_METHOD_FUNC(about), 0);
148
+ rb_define_method(c, "name", RUBY_METHOD_FUNC(get_name), 0);
149
+ rb_define_method(c, "name=", RUBY_METHOD_FUNC(set_name), 1);
150
+ }
@@ -0,0 +1,127 @@
1
+ #include "reflex/ruby/key.h"
2
+
3
+
4
+ #include <rucy.h>
5
+ #include "defs.h"
6
+
7
+
8
+ using namespace Rucy;
9
+
10
+
11
+ namespace Reflex
12
+ {
13
+
14
+
15
+ static Class cKey;
16
+
17
+ Class
18
+ key_class ()
19
+ {
20
+ return cKey;
21
+ }
22
+
23
+
24
+ }// Reflex
25
+
26
+
27
+ namespace Rucy
28
+ {
29
+
30
+
31
+ Value
32
+ value (const Reflex::Key& key)
33
+ {
34
+ return new_type<Reflex::Key>(
35
+ Reflex::key_class(), new Reflex::Key(key));
36
+ }
37
+
38
+
39
+ }// Rucy
40
+
41
+
42
+ struct RubyKey : public Reflex::Key
43
+ {
44
+
45
+ operator bool () const
46
+ {
47
+ return true;
48
+ }
49
+
50
+ bool operator ! () const
51
+ {
52
+ return !operator bool();
53
+ }
54
+
55
+ };// RubyKey
56
+
57
+
58
+ #define this ((RubyKey*) to<Reflex::Key*>(self))
59
+
60
+ #define CHECK CHECK_OBJECT(self, RubyKey, Reflex::key_class())
61
+
62
+
63
+ static
64
+ VALUE alloc(VALUE klass)
65
+ {
66
+ return new_type<RubyKey>(klass, new RubyKey);
67
+ }
68
+
69
+ static
70
+ VALUE initialize(VALUE self)
71
+ {
72
+ CHECK_OBJ(self, RubyKey, Reflex::key_class());
73
+ if (argc < 0 || 4 < argc)
74
+ argument_error("Key#initialize", argc, 0, 1, 2);
75
+
76
+ this->chars = (argc >= 1) ? argv[0].c_str() : NULL;
77
+ this->code = (argc >= 2) ? to<int>(argv[1]) : Reflex::KEY_NONE;
78
+ this->repeat = (argc >= 3) ? to<int>(argv[2]) : 1;
79
+ this->modifiers = (argc >= 4) ? to<uint>(argv[3]) : (uint) Reflex::MOD_NONE;
80
+
81
+ return self;
82
+ }
83
+
84
+ static
85
+ VALUE chars(VALUE self)
86
+ {
87
+ CHECK;
88
+ return value(this->chars.c_str());
89
+ }
90
+
91
+ static
92
+ VALUE code(VALUE self)
93
+ {
94
+ CHECK;
95
+ return value(this->code);
96
+ }
97
+
98
+ static
99
+ VALUE repeat(VALUE self)
100
+ {
101
+ CHECK;
102
+ return value(this->repeat);
103
+ }
104
+
105
+ static
106
+ VALUE modifiers(VALUE self)
107
+ {
108
+ CHECK;
109
+ return value(this->modifiers);
110
+ }
111
+
112
+
113
+ void
114
+ Init_key ()
115
+ {
116
+ Module m = rb_define_module("Reflex");
117
+
118
+ Class c = rb_define_class_under(m, "Key", rb_cObject);
119
+ Reflex::cKey = c;
120
+
121
+ rb_define_alloc_func(c, alloc);
122
+ rb_define_method(c, "initialize", RUBY_METHOD_FUNC(initialize), -1);
123
+ rb_define_method(c, "chars", RUBY_METHOD_FUNC(chars), 0);
124
+ rb_define_method(c, "code", RUBY_METHOD_FUNC(code), 0);
125
+ rb_define_method(c, "repeat", RUBY_METHOD_FUNC(repeat), 0);
126
+ rb_define_method(c, "modifiers", RUBY_METHOD_FUNC(modifiers), 0);
127
+ }
@@ -0,0 +1,26 @@
1
+ #include <rucy.h>
2
+ #include "defs.h"
3
+
4
+
5
+ using namespace Rucy;
6
+
7
+
8
+ void Init_reflex ();
9
+ void Init_application ();
10
+ void Init_window ();
11
+ void Init_key ();
12
+ void Init_points ();
13
+
14
+
15
+ extern "C" void
16
+ Init_native ()
17
+ {
18
+ if (!Rucy::init())
19
+ raise(rb_eLoadError, "Rucy::init() failed.");
20
+
21
+ Init_reflex();
22
+ Init_application();
23
+ Init_window();
24
+ Init_key();
25
+ Init_points();
26
+ }
@@ -0,0 +1,156 @@
1
+ #include "reflex/ruby/points.h"
2
+
3
+
4
+ #include <rucy.h>
5
+ #include "defs.h"
6
+
7
+
8
+ using namespace Rucy;
9
+
10
+ using Reflex::coord;
11
+
12
+
13
+ namespace Reflex
14
+ {
15
+
16
+
17
+ static Class cPoints;
18
+
19
+ Class
20
+ points_class ()
21
+ {
22
+ return cPoints;
23
+ }
24
+
25
+
26
+ }// Reflex
27
+
28
+
29
+ namespace Rucy
30
+ {
31
+
32
+
33
+ Value
34
+ value (const Reflex::Points& points)
35
+ {
36
+ return new_type<Reflex::Points>(
37
+ Reflex::points_class(), new Reflex::Points(points));
38
+ }
39
+
40
+
41
+ }// Rucy
42
+
43
+
44
+ struct RubyPoints : public Reflex::Points
45
+ {
46
+
47
+ operator bool () const
48
+ {
49
+ return true;
50
+ }
51
+
52
+ bool operator ! () const
53
+ {
54
+ return !operator bool();
55
+ }
56
+
57
+ };// RubyPoints
58
+
59
+
60
+ #define this ((RubyPoints*) to<Reflex::Points*>(self))
61
+
62
+ #define CHECK CHECK_OBJECT(self, RubyPoints, Reflex::points_class())
63
+
64
+
65
+ static
66
+ VALUE alloc(VALUE klass)
67
+ {
68
+ return new_type<RubyPoints>(klass, new RubyPoints);
69
+ }
70
+
71
+ static
72
+ VALUE initialize(VALUE self)
73
+ {
74
+ CHECK_OBJ(self, RubyPoints, Reflex::points_class());
75
+ if (argc < 0 || 6 < argc)
76
+ arg_count_error("Points#initialize", argc, 0, 1, 2, 3, 4, 5, 6);
77
+
78
+ this->type = (argc >= 1) ? to<int>(argv[0]) : Reflex::POINT_NONE;
79
+ this->x = (argc >= 2) ? to<coord>(argv[1]) : 0;
80
+ this->y = (argc >= 3) ? to<coord>(argv[2]) : 0;
81
+ this->size = 1;
82
+ this->modifiers = (argc >= 4) ? to<uint>(argv[3]) : (uint) Reflex::MOD_NONE;
83
+ this->count = (argc >= 5) ? to<uint>(argv[4]) : 0;
84
+ this->drag = (argc >= 6) ? to<bool>(argv[5]) : false;
85
+
86
+ return self;
87
+ }
88
+
89
+ static
90
+ VALUE type(VALUE self)
91
+ {
92
+ CHECK;
93
+ return value(this->type);
94
+ }
95
+
96
+ static
97
+ VALUE x(VALUE self)
98
+ {
99
+ CHECK;
100
+ return value(this->x);
101
+ }
102
+
103
+ static
104
+ VALUE y(VALUE self)
105
+ {
106
+ CHECK;
107
+ return value(this->y);
108
+ }
109
+
110
+ static
111
+ VALUE size(VALUE self)
112
+ {
113
+ CHECK;
114
+ return value(this->size);
115
+ }
116
+
117
+ static
118
+ VALUE modifiers(VALUE self)
119
+ {
120
+ CHECK;
121
+ return value(this->modifiers);
122
+ }
123
+
124
+ static
125
+ VALUE count(VALUE self)
126
+ {
127
+ CHECK;
128
+ return value(this->count);
129
+ }
130
+
131
+ static
132
+ VALUE drag(VALUE self)
133
+ {
134
+ CHECK;
135
+ return value(this->drag);
136
+ }
137
+
138
+
139
+ void
140
+ Init_points ()
141
+ {
142
+ Module m = rb_define_module("Reflex");
143
+
144
+ Class c = rb_define_class_under(m, "Points", rb_cObject);
145
+ Reflex::cPoints = c;
146
+
147
+ rb_define_alloc_func(c, alloc);
148
+ rb_define_method(c, "initialize", RUBY_METHOD_FUNC(initialize), -1);
149
+ rb_define_method(c, "type", RUBY_METHOD_FUNC(type), 0);
150
+ rb_define_method(c, "x", RUBY_METHOD_FUNC(x), 0);
151
+ rb_define_method(c, "y", RUBY_METHOD_FUNC(y), 0);
152
+ rb_define_method(c, "size", RUBY_METHOD_FUNC(size), 0);
153
+ rb_define_method(c, "modifiers", RUBY_METHOD_FUNC(modifiers), 0);
154
+ rb_define_method(c, "count", RUBY_METHOD_FUNC(count), 0);
155
+ rb_define_method(c, "drag", RUBY_METHOD_FUNC(drag), 0);
156
+ }
@@ -0,0 +1,72 @@
1
+ #include <rucy.h>
2
+ #include <reflex/reflex.h>
3
+ #include "defs.h"
4
+
5
+
6
+ using namespace Rucy;
7
+
8
+
9
+ namespace Reflex
10
+ {
11
+
12
+
13
+ static Module mReflex;
14
+
15
+ Module
16
+ reflex_module ()
17
+ {
18
+ return mReflex;
19
+ }
20
+
21
+
22
+ }// Reflex
23
+
24
+
25
+ static
26
+ VALUE init(VALUE self)
27
+ {
28
+ if (!Reflex::init())
29
+ error("Reflex::init() failed.");
30
+
31
+ return self;
32
+ }
33
+
34
+ static
35
+ VALUE fin(VALUE self)
36
+ {
37
+ if (!Reflex::fin())
38
+ error("Reflex::fin() failed.");
39
+
40
+ return self;
41
+ }
42
+
43
+ static
44
+ VALUE run(VALUE self, VALUE name)
45
+ {
46
+ if (!Reflex::run(name ? name.c_str() : NULL))
47
+ error("Reflex::run() failed.");
48
+
49
+ return self;
50
+ }
51
+
52
+ static
53
+ VALUE quit(VALUE self)
54
+ {
55
+ if (!Reflex::quit())
56
+ error("Reflex::quit() failed.");
57
+
58
+ return self;
59
+ }
60
+
61
+
62
+ void
63
+ Init_reflex ()
64
+ {
65
+ Module m = rb_define_module("Reflex");
66
+ Reflex::mReflex = m;
67
+
68
+ m.define_singleton_method("init!", init);
69
+ m.define_singleton_method("fin!", fin);
70
+ m.define_singleton_method("run!", run);
71
+ rb_define_singleton_method(m, "quit", RUBY_METHOD_FUNC(quit), 0);
72
+ }