diff options
Diffstat (limited to 'research')
-rw-r--r-- | research/oop2.sh | 54 |
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} |