summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2016-03-17 18:43:48 (EDT)
committer P. J. McDermott <pj@pehjota.net>2016-03-17 18:43:48 (EDT)
commit9d375eb403114a8cafc283ceed1158066650c8f4 (patch)
treecdb7b824ef6f623bd35dbeffd11f0eeae64b2989
parent0911f6ab9a29716d2b476728522b5b37d51391ed (diff)
downloadeggshell-9d375eb403114a8cafc283ceed1158066650c8f4.zip
eggshell-9d375eb403114a8cafc283ceed1158066650c8f4.tar.gz
eggshell-9d375eb403114a8cafc283ceed1158066650c8f4.tar.bz2
research: New arrays/OOP testing script
-rw-r--r--research/oop.sh94
1 files changed, 94 insertions, 0 deletions
diff --git a/research/oop.sh b/research/oop.sh
new file mode 100644
index 0000000..5e5dbf6
--- /dev/null
+++ b/research/oop.sh
@@ -0,0 +1,94 @@
+array_n=0
+
+array_new()
+{
+ array_n=$((${array_n} + 1))
+ retval="__arr_${array_n}"
+}
+
+array_set()
+{
+ local arr="${1}"
+ local idx="${2}"
+ local val="${3}"
+
+ eval "__arr_${arr}_${idx}=\${val}"
+}
+
+array_get()
+{
+ local arr="${1}"
+ local idx="${2}"
+
+ eval "retval=\${__arr_${arr}_${idx}}"
+}
+
+array_call()
+{
+ local arr="${1}"
+ local idx="${2}"
+ local fn=
+
+ eval "fn=\${__arr_${arr}_${idx}}"
+ "${fn}" ${arr}
+}
+
+color_new()
+{
+ local r="${1}"
+ local g="${2}"
+ local b="${3}"
+ local self=
+
+ array_new
+ self=${retval}
+ array_set ${self} r "${r}"
+ array_set ${self} g "${g}"
+ array_set ${self} b "${b}"
+ array_set ${self} print color_print
+
+ retval=${self}
+}
+
+color_get_r()
+{
+ local self="${1}"
+
+ array_get ${self} r
+}
+
+color_get_g()
+{
+ local self="${1}"
+
+ array_get ${self} g
+}
+
+color_get_b()
+{
+ local self="${1}"
+
+ array_get ${self} b
+}
+
+color_print()
+{
+ local self="${1}"
+
+ array_get ${self} r
+ printf '(%d, ' ${retval}
+ array_get ${self} g
+ printf '%d, ' ${retval}
+ array_get ${self} b
+ printf '%d)' ${retval}
+}
+
+color_new 255 0 0
+c=${retval}
+color_get_r ${c}
+printf 'R: %d\n' ${retval}
+color_get_g ${c}
+printf 'G: %d\n' ${retval}
+color_get_b ${c}
+printf 'B: %d\n' ${retval}
+array_call ${c} print