@@ -63,75 +63,10 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6363
6464*/
6565
66- /* API for adding a hook.
67-
68- An external user should call
69- add_pytutor_hook("hook_name_here", function(args) {...})
70- args will be a javascript object with several named properties;
71- this is meant to be similar to Python's keyword arguments.
72-
73- The hooked function should return an array whose first element is a boolean:
74- true if it completely handled the situation (no further hooks
75- nor the base function should be called); false otherwise (wasn't handled).
76- If the hook semantically represents a function that returns something,
77- the second value of the returned array is that semantic return value.
78-
79- E.g. for the Java visualizer a simplified version of a hook we use is:
80-
81- add_pytutor_hook(
82- "isPrimitiveType",
83- function(args) {
84- var obj = args.obj; // unpack
85- if (obj instanceof Array && obj[0] == "CHAR-LITERAL")
86- return [true, true]; // yes we handled it, yes it's primitive
87- return [false]; // didn't handle it, let someone else
88- });
89-
90- Hook callbacks can return false or undefined (i.e. no return
91- value) in lieu of [false].
92-
93- NB: If multiple functions are added to a hook, the oldest goes first.
94- */
95-
96- var add_pytutor_hook = function ( hook_name , func ) {
97- if ( pytutor_hooks [ hook_name ] )
98- pytutor_hooks [ hook_name ] . push ( ) ;
99- else
100- pytutor_hooks [ hook_name ] = [ func ] ;
101- }
102-
103- // this is global in order to reach static functions like isPrimitiveType
104- var pytutor_hooks = { } ; // keys, hook names; values, list of functions
105-
106- /*
107- try_hook(hook_name, args): how the internal codebase invokes a hook.
108- args will be a javascript object with several named properties;
109- this is meant to be similar to Python's keyword arguments.
110- E.g.,
111-
112- function isPrimitiveType(obj) {
113- var hook_result = try_hook("isPrimitiveType", {obj:obj});
114- if (hook_result[0]) return hook_result[1];
115- // go on as normal if the hook didn't handle it
116-
117- Although add_pytutor_hook allows the hooked function to
118- return false or undefined, try_hook will always return
119- something with the strict format [false], [true] or [true, ...].
120- */
121-
66+ // include hooks.js after you include pytutor.js, if you want to use hooks
67+ // see hooks.js for more instructions.
12268var try_hook = function ( hook_name , args ) {
123- if ( pytutor_hooks [ hook_name ] ) {
124- for ( var i = 0 ; i < pytutor_hooks [ hook_name ] . length ; i ++ ) {
125-
126- // apply w/o "this", and pack sole arg into array as required by apply
127- var handled_and_result
128- = pytutor_hooks [ hook_name ] [ i ] . apply ( null , [ args ] ) ;
129-
130- if ( handled_and_result && handled_and_result [ 0 ] )
131- return handled_and_result ;
132- }
133- }
134- return [ false ] ;
69+ return [ false ] ; // just a stub
13570}
13671
13772var SVG_ARROW_POLYGON = '0,3 12,3 12,0 18,5 12,10 12,7 0,7' ;
0 commit comments