summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2016-03-22 19:15:09 (EDT)
committer P. J. McDermott <pj@pehjota.net>2017-02-08 18:21:29 (EST)
commit39e8a092240b07bd4b39a7e327ea894610a9c14a (patch)
treef9b51c661edf1f6046cfac2e70067877ed615ebd
parentf2a198a6c4436fd4d30366f7071886c54ffc2658 (diff)
downloadeggshell-39e8a092240b07bd4b39a7e327ea894610a9c14a.zip
eggshell-39e8a092240b07bd4b39a7e327ea894610a9c14a.tar.gz
eggshell-39e8a092240b07bd4b39a7e327ea894610a9c14a.tar.bz2
research/oop2.sh: New file
-rw-r--r--research/oop2.sh54
1 files changed, 54 insertions, 0 deletions
diff --git a/research/oop2.sh b/research/oop2.sh
new file mode 100644
index 0000000..88e06db
--- /dev/null
+++ b/research/oop2.sh
@@ -0,0 +1,54 @@
+# Color.esh
+
+package Color
+
+r=
+g=
+b=
+
+new(string class, int r, int g, int b)
+{
+ local self=
+
+ self=$[malloc]
+ bless ${self} ${class}
+ self->r="${r}"
+ self->g="${g}"
+ self->b="${b}"
+}
+
+delete(int self)
+{
+ unset self->r
+ unset self->g
+ unset self->b
+ free ${self}
+}
+
+get_r(int self)
+{
+ retval=${self->r}
+}
+
+get_g(int self)
+{
+ retval=${self->g}
+}
+
+get_b(int self)
+{
+ retval=${self->b}
+}
+
+print(int self)
+{
+ printf '(%d, %d, %d)' ${self->r} ${self->g} ${self->b}
+}
+
+# main.esh
+
+c=$[${Color::new} 255 0 0]
+printf 'R: %d\n' "$[${c->get_r}]"
+printf 'G: %d\n' "$[${c->get_g}]"
+printf 'B: %d\n' "$[${c->get_b}]"
+${c->print}