cappruby 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/framework/hash.js ADDED
@@ -0,0 +1,109 @@
1
+ /*
2
+ * hash.js
3
+ * cappruby
4
+ *
5
+ * Created by Adam Beynon.
6
+ * Copyright 2010 Adam Beynon.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+
27
+ rb_cHash = nil;
28
+
29
+ /**
30
+ Create a new hash. Only called from JS. args are keys and values, so:
31
+ key1, val1, key2, val2, .......keyN, valN.
32
+ */
33
+ function rb_hash_new() {
34
+ var k, v, h = new objj_dictionary();
35
+ for (var i = 0; i < arguments.length; i++) {
36
+ k = arguments[i], v = arguments[i+1];
37
+ i ++;
38
+ dictionary_setValue(h, k, v);
39
+ }
40
+ return h;
41
+ };
42
+
43
+ function rb_hash_delete(hash, sel, id) {
44
+ var r = dictionary_getValue(hash, id);
45
+ dictionary_removeValue(hash, id);
46
+ return r;
47
+ };
48
+
49
+ function rb_hash_merge(hash, sel, options) {
50
+ return objj_msgSend(hash, "addEntriesFromDictionary:", options);
51
+ };
52
+
53
+
54
+ function Init_Hash() {
55
+ rb_cHash = objj_getClass("CPDictionary");
56
+ rb_const_set(rb_cObject, "Hash", rb_cHash);
57
+
58
+ // rb_include_module(rb_cHash, rb_mEnumerable);
59
+
60
+ // rb_define_singleton_method(rb_cHash, "[]", rb_hash_s_create, -1);
61
+ // rb_define_singleton_method(rb_cHash, "try_convert", rb_hash_s_try_convert, 1);
62
+ rb_define_method(rb_cHash, "initialize", rb_hash_initialize, -1);
63
+
64
+ // rb_define_method(rb_cHash, "to_hash", rb_hash_to_hash, 0);
65
+ // rb_define_method(rb_cHash, "to_a", rb_hash_to_a, 0);
66
+ // rb_define_method(rb_cHash, "to_s", rb_hash_inspect, 0);
67
+ // rb_define_method(rb_cHash, "inspect", rb_hash_inspect, 0);
68
+
69
+ // rb_define_method(rb_cHash, "==", rb_hash_equal, 1);
70
+ // rb_define_method(rb_cHash, "[]", rb_hash_aref, 1);
71
+ // rb_define_method(rb_cHash, "eql?", rb_hash_eql, 1);
72
+ // rb_define_method(rb_cHash, "fetch", rb_hash_fetch, -1);
73
+ // rb_define_method(rb_cHash, "[]=", rb_hash_aset, 2);
74
+ // rb_define_method(rb_cHash, "store", rb_hash_aset, 2);
75
+ // rb_define_method(rb_cHash, "default", rb_hash_default, -1);
76
+ // rb_define_method(rb_cHash, "default=", rb_hash_set_default, 1);
77
+ // rb_define_method(rb_cHash, "default_proc", rb_hash_default_proc, 0);
78
+ // rb_define_method(rb_cHash, "key", rb_hash_key, 1);
79
+ // rb_define_method(rb_cHash, "index", rb_hash_index, 1);
80
+ // rb_define_method(rb_cHash, "size", rb_hash_size, 0);
81
+ // rb_define_method(rb_cHash, "length", rb_hash_size, 0);
82
+ // rb_define_method(rb_cHash, "empty?", rb_hash_empty_p, 0);
83
+
84
+ // rb_define_method(rb_cHash, "each_value", rb_hash_each_value, 0);
85
+ // rb_define_method(rb_cHash, "each_key", rb_hash_each_key, 0);
86
+ // rb_define_method(rb_cHash, "each_pair", rb_hash_each_pair, 0);
87
+ // rb_define_method(rb_cHash, "each", rb_hash_each_pair, 0);
88
+
89
+ // rb_define_method(rb_cHash, "keys", rb_hash_keys, 0);
90
+ // rb_define_method(rb_cHash, "values", rb_hash_values, 0);
91
+ // rb_define_method(rb_cHash, "values_at", rb_hash_values_at, -1);
92
+
93
+ // rb_define_method(rb_cHash, "shift", rb_hash_shift, 0);
94
+ rb_define_method(rb_cHash, "delete:", rb_hash_delete, 1);
95
+ // rb_define_method(rb_cHash, "delete_if", rb_hash_delete_if, 0);
96
+ // rb_define_method(rb_cHash, "select", rb_hash_select, 0);
97
+ // rb_define_method(rb_cHash, "reject", rb_hash_reject, 0);
98
+ // rb_define_method(rb_cHash, "reject!", rb_hash_reject_bang, 0);
99
+ // rb_define_method(rb_cHash, "clear", rb_hash_clear, 0);
100
+ // rb_define_method(rb_cHash, "invert", rb_hash_invert, 0);
101
+
102
+ // rb_define_method(rb_cHash, "update", rb_hash_update, 1);
103
+ // rb_define_method(rb_cHash, "replace", rb_hash_replace, 1);
104
+ // rb_define_method(rb_cHash, "merge!", rb_hash_update, 1);
105
+ rb_define_method(rb_cHash, "merge:", rb_hash_merge, 1);
106
+ // rb_define_method(rb_cHash, "assoc", rb_hash_assoc, 1);
107
+ // rb_define_method(rb_cHash, "rassoc", rb_hash_rassoc, 1);
108
+ // rb_define_method(rb_cHash, "flatten", rb_hash_flatten, -1);
109
+ };
@@ -0,0 +1,86 @@
1
+ /*
2
+ * mapings.js
3
+ * cappruby
4
+ *
5
+ * Created by Adam Beynon.
6
+ * Copyright 2010 Adam Beynon.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+
27
+ /**
28
+ Mappings are a port/inspired of the Hotcocoa mappings
29
+ */
30
+
31
+ /**
32
+ Stores all "default" options that can be used by mappings.
33
+ */
34
+ cr_mappings_defaults_store = nil;
35
+
36
+ /**
37
+ Setup the defaults. We do not want to do this until we can use the hash, so we
38
+ pop it into the Init_x functions call sequences.
39
+ */
40
+ function cr_mappings_default_init() {
41
+ cr_mappings_defaults_store = {
42
+
43
+ 'window': rb_hash_new(
44
+ // window title
45
+ ID2SYM("title"), "Window",
46
+ // frame can be an array, which is automatically converted into a rect
47
+ ID2SYM("frame"), [100, 100, 400, 500]
48
+ )
49
+ };
50
+ };
51
+
52
+ /**
53
+ merge default and given options
54
+
55
+ our options need to be merged into our defaults, so our user options will
56
+ overwrite the defaults where new ones are specified, or use the old ones
57
+ where they are not specified.
58
+ */
59
+ function cr_mappings_collate_options(name, options) {
60
+ var h = new objj_dictionary();
61
+ rb_hash_merge(h, 'merge', cr_mappings_defaults_store[name]);
62
+ rb_hash_merge(h, 'merge', options);
63
+ return h;
64
+ };
65
+
66
+ /**
67
+ Once important options have been set, the rest can be applied to any given
68
+ object by assuming they have kvo setters to set the properties.
69
+
70
+ Important options should be #delete! from the hash, so when it is given here,
71
+ they will not be reset.
72
+ */
73
+ function cr_mappings_set_options(obj, hash) {
74
+
75
+ };
76
+
77
+ /**
78
+ Initialize mappings. All methods are added to Kernel module to avoid
79
+ over populating the Object namespace. (hide from Cappuccino).
80
+ */
81
+ function Init_Mappings() {
82
+ // setup defaults.
83
+ cr_mappings_default_init();
84
+ Init_Mappings_Window();
85
+ Init_Mappings_Geometry();
86
+ };
@@ -0,0 +1,120 @@
1
+ /*
2
+ * method.js
3
+ * cappruby
4
+ *
5
+ * Created by Adam Beynon.
6
+ * Copyright 2010 Adam Beynon.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+
27
+ /**
28
+ cappruby method. Similar to objj_method, but takes extra "ruby specific" bits
29
+ and pieces.
30
+ */
31
+ function cappruby_method_t(name, imp, types) {
32
+ this.name = name;
33
+ this.method_imp = imp;
34
+ this.types = types;
35
+
36
+ // this is set to true if the method is a cappruby method
37
+ this.capprubymethod = true;
38
+ // arity
39
+ this.arity = 0;
40
+ };
41
+
42
+ /**
43
+ global functions. Some methods in ruby can be defined as "global functions".
44
+ These all begin with uppercase lettters, and look like constants. All global
45
+ functions are stored in this table. As an exception for objj, searching for
46
+ global functions will first search this table, and then, search the global
47
+ namespace. This will allow CoreGraphics, CGRect, CPApplicationMain etc all to
48
+ become available to ruby. Note, with global functions, no "self" property is
49
+ used. This allows functions from objj to be seemesly used.
50
+ */
51
+ rb_global_functions_table = { };
52
+
53
+ function rb_global_functions_search(id) {
54
+ if (rb_global_functions_table[id]) {
55
+ return rb_global_functions_table[id];
56
+ }
57
+ // if found in window/global, ensure it is a function.
58
+ else if (window[id] && typeof window[id] === 'function') {
59
+ return window[id];
60
+ }
61
+ // not found..
62
+ return nil;
63
+ };
64
+
65
+ /**
66
+ Search for the method in klass. Additons to objj search are that it searches
67
+ modules as well, which are attatched to classes via rb_included_modules.
68
+ */
69
+ function rb_search_method(klass, id) {
70
+ var m = klass.method_dtable[id];
71
+
72
+ if (!m) {
73
+ // this whole loop is to look for included moduels. method_dtable takes care
74
+ // of all inherited methods. Also, by definitoons, look at methods on class
75
+ // before included methods...
76
+ while (klass) {
77
+ if (klass.rb_included_modules) {
78
+ for (var i = 0; i < klass.rb_included_modules.length; i++) {
79
+ if (m = klass.rb_included_modules[i].method_dtable[id]) {
80
+ break;
81
+ }
82
+ }
83
+ if (m) break;
84
+ }
85
+ klass = klass.super_class;
86
+ }
87
+ // if we found it
88
+ if (m) return m.method_imp;
89
+ return nil;
90
+ }
91
+ // if found straight away..
92
+ return m.method_imp;
93
+ };
94
+
95
+ /**
96
+ If we dont have a .isa property, find out the type of class. We can, for
97
+ instance, guess its a rect/point/size etc, and add a .isa property to it for
98
+ the future. If all else fails, we assume it to be a regular JSON object. In
99
+ this case, we must return the WrapperJSON class. WrapperJSON does not add a
100
+ .isa property, as this could muck up json properties of the object (e.g. a
101
+ property that shouldnt really exist), so the class is a Wrapper class that can
102
+ interact with any nominal object. CPRect, CPPoint and CPSize .isa properties
103
+ will be added, as they wont affect the nature of these structs.
104
+ */
105
+ function rb_find_class_for_obj(obj) {
106
+ if (obj.hasOwnProperty('size') && obj.hasOwnProperty('origin')) {
107
+ obj.isa = cr_cRect;
108
+ return cr_cRect;
109
+ }
110
+ else if (obj.hasOwnProperty('width') && obj.hasOwnProperty('height')) {
111
+ obj.isa = cr_cSize;
112
+ return cr_cSize;
113
+ }
114
+ else if (obj.hasOwnProperty('x') && obj.hasOwnProperty('y')) {
115
+ obj.isa = cr_cPoint;
116
+ return cr_cPoint;
117
+ }
118
+ console.log(obj);
119
+ throw "trying to find class for obj - must be JSON, so use JSONWrapper"
120
+ };
@@ -0,0 +1,72 @@
1
+ /*
2
+ * module.js
3
+ * cappruby
4
+ *
5
+ * Created by Adam Beynon.
6
+ * Copyright 2010 Adam Beynon.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+
27
+ function rb_module_new() {
28
+ return rb_define_module_id("");
29
+ };
30
+
31
+ function rb_define_module_id(id) {
32
+ var m;
33
+ m = rb_objj_alloc_class(id, rb_cObject, T_MODULE, rb_cModule);
34
+ return m;
35
+ };
36
+
37
+ function rb_define_module(id) {
38
+ var m;
39
+ if (rb_const_defined(rb_cObject, id)) {
40
+ m = rb_const_get(rb_cObject, id);
41
+ // check tyoe
42
+ return m;
43
+ }
44
+ m = rb_define_module_id(id);
45
+ rb_const_set(rb_cObject, id, m);
46
+ return m;
47
+ };
48
+
49
+ /**
50
+ Objj wont natively support including modules, so instead, modules
51
+ are added to class's meta classes in an array, so rb_funcall can
52
+ check there if a method is not found otherwise. This is correct
53
+ behaviour as methods defined in modules, then included, should
54
+ be checked after method defined on a class itself. Note, because
55
+ we use this, objj_msgSend cannot be used: rb_funcall must be used
56
+ instead.
57
+
58
+ Also, these are stores on the klass in which the module was included.
59
+ For that reason, the entire inheritance stack must be searched all the
60
+ way back to CPObject (i.e. no more superclass.)
61
+
62
+ This will only happen on module methods, not all the time, so there
63
+ wont be that much performance impact.
64
+ */
65
+ function rb_include_module(klass, module) {
66
+ // make array if not already present
67
+ if (!klass.rb_included_modules) klass.rb_included_modules = [];
68
+ // might already be included
69
+ if (klass.rb_included_modules.indexOf(module) != -1) return;
70
+ // else, push it on
71
+ klass.rb_included_modules.push(module);
72
+ };
@@ -0,0 +1,128 @@
1
+ /*
2
+ * object.js
3
+ * opal
4
+ *
5
+ * Created by Adam Beynon.
6
+ * Copyright 2010 Adam Beynon.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+
27
+ rb_cObject = nil;
28
+ rb_cBasicObject = nil;
29
+ rb_cModule = nil;
30
+ rb_cClass = nil;
31
+ rb_mKernel = nil;
32
+
33
+ function rb_basic_obj_alloc(cls, sel) {
34
+ return class_createInstance(cls);
35
+ };
36
+
37
+ function rb_module_s_alloc(mod, sel) {
38
+ return rb_module_new();
39
+ };
40
+
41
+ function rb_class_s_alloc(cls, sel) {
42
+ return rb_class_boot();
43
+ };
44
+
45
+ function rb_f_puts(cls, sel, val) {
46
+ console.log(val);
47
+ // CPLog(val);
48
+ return nil;
49
+ };
50
+
51
+ function rb_mod_attr_accessor(cls, sel) {
52
+ var i, a = Array.prototype.slice.call(arguments, 2);
53
+ for (i = 0; i < a.length; i++) {
54
+ rb_objj_define_kvo_getter(cls, a[i]);
55
+ rb_objj_define_kvo_setter(cls, a[i]);
56
+ }
57
+ return cls;
58
+ };
59
+
60
+ function rb_mod_attr_reader(cls, sel) {
61
+ var i, a = Array.prototype.slice.call(arguments, 2);
62
+ for (i = 0; i < a.length; i++) {
63
+ rb_objj_define_kvo_getter(cls, a[i]);
64
+ }
65
+ return cls;
66
+ };
67
+
68
+ function rb_mod_attr_writer(cls, sel) {
69
+ var i, a = Array.prototype.slice.call(arguments, 2);
70
+ for (i = 0; i < a.length; i++) {
71
+ rb_objj_define_kvo_setter(cls, a[i]);
72
+ }
73
+ return cls;
74
+ };
75
+
76
+ function rb_objj_define_kvo_setter(cls, id) {
77
+ id = objj_msgSend(id, "to_s");
78
+ var k = "set" + id.charAt(0).toUpperCase() + id.substr(1) + ":";
79
+ rb_define_method(cls, k, function(self, sel, val) {
80
+ var key = id;
81
+ return rb_ivar_set(self, key, val);
82
+ }, 1);
83
+ };
84
+
85
+ function rb_objj_define_kvo_getter(cls, id) {
86
+ id = objj_msgSend(id, "to_s");
87
+ rb_define_method(cls, id, function(self, sel, val) {
88
+ var key = id;
89
+ return rb_ivar_get(self, id);
90
+ }, 0);
91
+ };
92
+
93
+ function Init_Object() {
94
+
95
+ rb_cObject = objj_getClass("CPObject");
96
+ rb_const_set(rb_cObject, "Object", rb_cObject);
97
+
98
+ rb_cBasicObject = objj_allocateClassPair(null, 'BasicObject');
99
+ rb_const_set(rb_cObject, "BasicObject", rb_cBasicObject);
100
+ rb_define_singleton_method(rb_cBasicObject, "alloc", rb_basic_obj_alloc, 0);
101
+
102
+ rb_cModule = boot_defclass("Module", rb_cObject);
103
+ rb_cClass = boot_defclass("Class", rb_cModule);
104
+
105
+ rb_define_singleton_method(rb_cModule, "alloc", rb_module_s_alloc, 0);
106
+ rb_define_singleton_method(rb_cClass, "alloc", rb_class_s_alloc, 0);
107
+
108
+ rb_include_module(rb_cObject.isa, rb_cClass);
109
+ rb_include_module(rb_cObject.isa, rb_cModule);
110
+
111
+
112
+
113
+
114
+ rb_mKernel = rb_define_module("Kernel");
115
+ rb_include_module(rb_cObject, rb_mKernel);
116
+
117
+ /**
118
+ puts is generally called with a single param, so we use a colon-iszed name
119
+ for quicker lookups (to save having to reaearch without a colon)
120
+ */
121
+ rb_define_method(rb_mKernel, "puts:", rb_f_puts, 1);
122
+ rb_define_method(rb_cModule, "puts:", rb_f_puts, 1);
123
+
124
+ // rb_define_method(rb_cModule, "attr:", rb_mod_attr, -1);
125
+ rb_define_method(rb_cModule, "attr_reader:", rb_mod_attr_reader, -1);
126
+ rb_define_method(rb_cModule, "attr_writer:", rb_mod_attr_writer, -1);
127
+ rb_define_method(rb_cModule, "attr_accessor:", rb_mod_attr_accessor, -1);
128
+ };
@@ -0,0 +1,84 @@
1
+ /*
2
+ * objj_additions.js
3
+ * opal
4
+ *
5
+ * Created by Adam Beynon.
6
+ * Copyright 2010 Adam Beynon.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+
27
+ /**
28
+ Stuff in here are things that are generally useful, and could be implemented
29
+ as part of vanilla objj.
30
+ */
31
+
32
+ /**
33
+ Types: useful for identifying types of objects: extends CLS, OBJ types.
34
+ */
35
+ T_CLASS = 0;
36
+ T_MODULE = 1;
37
+ T_OBJECT = 2;
38
+ T_ICLASS = 3;
39
+ T_STRING = 4;
40
+ T_ARRAY = 5;
41
+ T_NUMBER = 6;
42
+ T_PROC = 7;
43
+ T_SYMBOL = 8;
44
+ T_HASH = 9;
45
+ T_BOOLEAN = 10;
46
+
47
+ // type support
48
+ Number.prototype.objj_flags = T_NUMBER;
49
+ Array.prototype.objj_flags = T_ARRAY;
50
+ Boolean.prototype.objj_flags = T_BOOLEAN;
51
+ Function.prototype.objj_flags = T_PROC;
52
+
53
+ /**
54
+ CLS_SINGLETON
55
+
56
+ Identifiy objects as singletons (or more specifically, classes)
57
+
58
+ This is also a "nicer" way for handling KVO replacing classes.. makes the idea
59
+ more generic.
60
+ */
61
+ CLS_SINGLETON = 0x16;
62
+
63
+ /**
64
+ Duplicate class - for now a hack, need to actually do this.
65
+ */
66
+ function objj_duplicateClass(klass, name) {
67
+ var c = objj_allocateClassPair(klass, name);
68
+
69
+ objj_registerClassPair(c);
70
+ _class_initialize(c);
71
+ return c;
72
+ };
73
+
74
+ /**
75
+ Proc/Block/Func
76
+ */
77
+ @implementation CPBlock : CPObject
78
+ {
79
+
80
+ }
81
+
82
+ @end
83
+
84
+ Function.prototype.isa = CPBlock;
data/framework/proc.js ADDED
@@ -0,0 +1,31 @@
1
+ /*
2
+ * proc.js
3
+ * cappruby
4
+ *
5
+ * Created by Adam Beynon.
6
+ * Copyright 2010 Adam Beynon.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+
27
+ rb_cProc = nil;
28
+
29
+ function Init_Proc() {
30
+ rb_cProc = objj_getClass("CPBlock");
31
+ };