From a6d58bb6052ac8cb01805a48c4ad2f129126116f Mon Sep 17 00:00:00 2001 From: tpearson Date: Wed, 24 Feb 2010 02:13:59 +0000 Subject: Added KDE3 version of kvirc git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kvirc@1095341 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- doc/scriptexamples/class1.kvs | 102 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 doc/scriptexamples/class1.kvs (limited to 'doc/scriptexamples/class1.kvs') diff --git a/doc/scriptexamples/class1.kvs b/doc/scriptexamples/class1.kvs new file mode 100644 index 00000000..6098000d --- /dev/null +++ b/doc/scriptexamples/class1.kvs @@ -0,0 +1,102 @@ +# Example of object function overriding and calling +# This is quite intricated...try to get out of this +# by examining the code. + +class (A,object) +{ + # The base class at all + # Implements $A::function and $A::virtual + function + { + echo -i=10 "$0\Entering A::function()" + $$->$virtual("----$0") + echo -i=10 "$0\Exiting A::function()" + } + virtual + { + echo -i=10 "$0\This is A::virtual()" + } +} + +class (B,A) +{ + # Derived from A : inherits $A::function() + # overrides $A::virtual + virtual + { + echo -i=20 "$0\Entering B::virtual()" + $$->$A::virtual("----$0") + echo -i=20 "$0\Exiting B::virtual()" + } +} + +class (C,B) +{ + # Derived from B : inherits $B::virtual and + # overrides $B::function (that is $A::function) + function + { + echo -i=30 "$0\This is C::function" + } +} + +echo -i=7 "Ok...now try to gusess what's going on :)" + +%o = $new(C,0,test) + +echo "# Calling \%o->\$function" +%o->$function +echo "# Calling \%o->\$C::function" +%o->$C::function +echo "# Calling \%o->\$B::function" +%o->$B::function +echo "# Calling \%o->\$A::function" +%o->$A::function +echo "# Implementing private \%o->\$function" +privateimpl(%o,function) +{ + # This is a private implementation that + # overrides $C::function + echo "$0\Entering \$\$::function" + $$->$C::function("----$0"); + echo "$0\Exiting \$\$::function" +} + +echo "# Calling \%o->\$function" +%o->$function +echo "# Calling \%o->\$C::function" +%o->$C::function +echo "# Calling \%o->\$B::function" +%o->$B::function +echo "# Calling \%o->\$A::function" +%o->$A::function +echo "# Implementing private \%o->\$virtual" +privateimpl(%o,virtual) +{ + # This is a private implementation that + # overrides $C::virtual (that is $B::virtual in fact) + echo "$0\Entering \$\$::virtual" + $$->$C::virtual("----$0") + echo "$0\Exiting \$\$::virtual" +} + +echo "# Calling \%o->\$function" +%o->$function +echo "# Calling \%o->\$C::function" +%o->$C::function +echo "# Calling \%o->\$B::function" +%o->$B::function +echo "# Calling \%o->\$A::function" +%o->$A::function +echo "# Removing private \%o->\$function" +privateimpl(%o,function){} +echo "# Calling \%o->\$function" +%o->$function +echo "# Calling \%o->\$C::function" +%o->$C::function +echo "# Calling \%o->\$B::function" +%o->$B::function +echo "# Calling \%o->\$A::function" +%o->$A::function + +delete %o -- cgit v1.2.1