From d4a7290707cb323b565ef07e76366a35c71fe8ec Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Tue, 28 Dec 2021 20:58:07 +0100 Subject: [PATCH] "using" directive, static classes, proper examples, declared objects are nom recommanded to be accessed using the $ prefix like all other variables. --- example/Example.shn | 3 +++ example/Static.shc | 6 ++++++ example/script.sh | 29 +++++++++++++++++++++++------ 3 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 example/Static.shc diff --git a/example/Example.shn b/example/Example.shn index 24a833c..11f8b03 100644 --- a/example/Example.shn +++ b/example/Example.shn @@ -5,3 +5,6 @@ namespace Example # Object declaration, from class name to file name. class Object "Object.shc" + +# Static class declaration +static_class Static "Static.shc" diff --git a/example/Static.shc b/example/Static.shc new file mode 100644 index 0000000..1e08ce3 --- /dev/null +++ b/example/Static.shc @@ -0,0 +1,6 @@ + +# Function declaration. +# NOTE: Properties can't be declared for static classes +Static.print() { + echo "$@" +} diff --git a/example/script.sh b/example/script.sh index d86c616..8d0b368 100644 --- a/example/script.sh +++ b/example/script.sh @@ -3,14 +3,31 @@ OOP_ROOT=.. . $OOP_ROOT/oop.sh # Import library. +# Import library importNamespace Example.shn -Example.Object t1 "Test" -Example.Object t2 "Example" +# OOP Example +Example.Object obj1 "First Object" +Example.Object obj2 "Second Object" -t1.print -t2.print +$obj1.print +# The $ is not mandatory, but is recommanded. +obj2.print -t1.name = "New name" +objs=($obj1 $obj2) +${objs[0]}.print +${objs[1]}.print -t1.print +$obj1.name = "New name" + +$obj1.print + +# Static example +Example.Static.print "Example text" + +# Using directive. +using Example + +Object usingObj "New" + +$usingObj.print