3 # This file illustrates the cross language polymorphism using directors.
7 OctCallback=@() subclass(example.Callback(), \
8 'run',@(self) printf("OctCallback.run()\n"));
10 # Create an Caller instance
12 caller = example.Caller();
14 # Add a simple C++ callback (caller owns the callback, so
17 printf("Adding and calling a normal C++ callback\n");
18 printf("----------------------------------------\n");
20 callback = example.Callback().__disown();
21 caller.setCallback(callback);
25 printf("Adding and calling a Octave callback\n");
26 printf("------------------------------------\n");
28 # Add a Octave callback (caller owns the callback, so we
29 # disown it first by calling __disown).
31 caller.setCallback(OctCallback().__disown())
35 printf("Adding and calling another Octave callback\n");
36 printf("------------------------------------------\n");
38 # Let's do the same but use the weak reference this time.
40 callback = OctCallback().__disown();
41 caller.setCallback(callback);
45 # careful-- using callback here may cause problems; octave_swig_type still
46 # exists, but is holding a destroyed object (the C++ example.Callback).
47 # to manually drop the octave-side reference, you can use
50 # Let's call them directly now
52 printf("Calling Octave and C++ callbacks directly\n");
53 printf("------------------------------------------\n");
62 printf("octave exit\n");